import { injectable , inject } from "inversify" ; import TYPES from "../../common/types" ; import { SystemFailureInstance } from "./system-failure.model" ; import { SystemFailureDto } from "./system-failure.dto" ; import { SystemFailureDao } from "./system-failure.dao" ; interface SystemFailureService { getSystemFailure ( system ? , begin ? , end ? , limit ? ) : Promise < Array < SystemFailureDto > > ; saveSystemFailure ( systemFailure ) : Promise < Array < SystemFailureDto > > ; } @ injectable ( ) class SystemFailureServiceImpl implements SystemFailureService { constructor ( @ inject ( TYPES . SystemFailureDao ) private systemFailureDao ) { } private convertToDto ( systemFailureInstance ) { let systemFailureDto = { id : systemFailureInstance . id , time : systemFailureInstance . time , system : systemFailureInstance . system , host : systemFailureInstance . host , url : systemFailureInstance . url , status : systemFailureInstance . status } ; return systemFailureDto ; } public getSystemFailure ( system ? , begin ? , end ? , limit ? ) { return this . systemFailureDao . getSystemFailure ( system , begin , end , limit ) . then ( ( systemFailures ) => { return systemFailures . map ( this . convertToDto ) ; } ) ; } public saveSystemFailure ( systemFailures ) { return this . systemFailureDao . saveSystemFailure ( systemFailures ) . then ( ( failures ) => { return failures . map ( this . convertToDto ) ; } ) ; } } export { SystemFailureService , SystemFailureServiceImpl } ;