import { injectable , inject } from "inversify" ; import TYPES from "../../common/types" ; import * as express from "express" ; import { SystemInfoService } from "./system-info.service" ; import { SystemInfoMapDto , SystemInfoDetailMapDto } from "./system-info.dto" ; import { ResponseWriter } from "../../common/response-writer" ; interface SystemInfoController { getRouter ( ) : express . Router ; } @ injectable ( ) class SystemInfoControllerImpl implements SystemInfoController { private errorHandler = ( res , next ) => { return ( err ) => { next ( err ) ; } ; } ; constructor ( @ inject ( TYPES . SystemInfoService ) private systemInfoService ) { } public getRouter ( ) { let router = express . Router ( ) ; router . get ( "/list" , this . getSystemList ) ; router . get ( "/:system" , this . getSystemInfo ) ; return router ; } private getSystemList = ( req , res , next ) : void => { this . systemInfoService . getSystemList ( ) . then ( ( systemList ) => { ResponseWriter . success ( res , systemList ) ; } ) . then ( null , this . errorHandler ( res , next ) ) ; } ; private getSystemInfo = ( req , res , next ) : void => { let system = req . params . system ; let detail = req . query . detail === "true" ; let begin = parseInt ( req . query . begin ) ; let end = parseInt ( req . query . end ) ; let count = parseInt ( req . query . count ) ; if ( system === null ) { ResponseWriter . success ( res , [ ] ) ; return ; } if ( detail ) { this . systemInfoService . getSystemInfoDetail ( system , begin , end , count ) . then ( ( systemInfoList ) => { ResponseWriter . success ( res , systemInfoList ) ; } ) . then ( null , this . errorHandler ( res , next ) ) ; } else { this . systemInfoService . getSystemInfo ( system , begin , end , count ) . then ( ( systemInfoList ) => { ResponseWriter . success ( res , systemInfoList ) ; } ) . then ( null , this . errorHandler ( res , next ) ) ; } } ; } export { SystemInfoController , SystemInfoControllerImpl } ;