import { ApiController , Controller , HttpGet , SendsResponse , Async , Deferrer , Returns } from '../../../../index' ; import { IAboutService } from '../services/about.service' ; import { About } from '../model/about.model' ; @ Controller ( '/home' ) export class HomeController extends ApiController { private name : string ; constructor ( private aboutService ) { super ( ) ; this . name = 'HomeController' ; } @ HttpGet ( '/filters' ) get ( ) { this . response . locals . data . push ( this . name ) ; return this . response . locals . data ; } @ SendsResponse ( ) @ HttpGet ( '/image/:id' ) imageId ( id ) { setTimeout ( ( ) => { this . dino . proceed ( `Value of id is ${ id }` ) ; } , 100 ) ; } @ SendsResponse ( ) @ HttpGet ( '/dino-throw' ) imageThrow ( id ) { setTimeout ( ( ) => { this . dino . throw ( new Error ( 'SyncTestExceptionOne is thrown' ) ) ; } , 100 ) ; } @ HttpGet ( '/sync-error-one' ) syncThrowOne ( ) { throw new Error ( 'SyncTestExceptionOne is thrown' ) ; } @ HttpGet ( '/sync-error-two' ) syncThrowTwo ( ) { throw new Error ( 'SyncTestExceptionTwo is thrown' ) ; } @ HttpGet ( '/error-controller' ) errorController ( ) { throw new Error ( 'ErrorController must handle this' ) ; } @ Async ( ) @ HttpGet ( '/async-data' ) async getAsyncData ( ) { return await Deferrer . run < string > ( ( resolve , reject ) => { setTimeout ( ( ) => resolve ( 'This is AsyncData' ) , 10 ) ; } ) ; } @ Async ( ) @ HttpGet ( '/await-about' ) async getViaAwait ( ) { return await this . aboutService . getViaPromise ( ) ; } @ Async ( ) @ HttpGet ( '/async-throw' ) async getUsersThrow ( ) { throw new Error ( 'Synchronous exception thrown with @Async Attribute' ) ; } @ Async ( ) @ HttpGet ( '/promise-error' ) async getViaPromiseError ( ) { return await this . aboutService . getViaPromiseError ( ) ; } @ Returns ( { schema : '$type' } ) @ HttpGet ( '/returns' ) getReturnsData ( ) { return 'ReturnsData' ; } @ Async ( ) @ Returns ( { schema : '$asyncType' } ) @ HttpGet ( '/returnsAsync' ) async getReturnsAsyncData ( ) { return await Deferrer . run < string > ( ( resolve , reject ) => { setTimeout ( ( ) => resolve ( 'ReturnsAsyncData' ) , 10 ) ; } ) ; } }