import { DyNTS_Endpoint_Params } from '../../_models/control-models/endpoint-params.control-model'; import { DyNTS_SingletonService } from '../base/singleton.service'; /** * Basic controller for endpoint handlings * * (You'll need to add them to a {@link DyNTS_RoutingModule} through it's constructor) * * You can add default endpoints to the controller by using the {@link DyNTS_DefaultEndpoints_Util} utility class * * @example * this.endpoints = [ * ...DyNTS_DefaultEndpoints_Util.getAllDefaultEndpoints({ * entityName: 'UserMatchStatistics', * dataServiceClass: UserMatchStatistics_DataService, * endpoints: { * get: '/get/user-match-statistics/:userId', * search: '/search/user-match-statistics', * modify: '/modify/user-match-statistics', * patch: '/patch/user-match-statistics/:userId', * delete: '/delete/user-match-statistics/:userId', * }, * authService: this.authService, * }), * ]; * * @example * export class UserMatchStatisticsController extends DyNTS_Controller { * * static getInstance(): UserMatchStatisticsController { * return UserMatchStatisticsController.getSingletonInstance(); * } * * // SERVICES * private authService: AuthService; * * setupEndpoints(): void { * this.authService = AuthService.getInstance(); * * this.endpoints = [ * new DyNTS_Endpoint_Params({ * name: 'getUserMatchStatistics', * type: DyFM_HttpCallType.get, * endpoint: '/get/user-match-statistics/:userId', * preProcesses: [ this.authService.authenticate_tokenSelf ], * tasks: [ * async (req: Request, res: Response) => { * const userMatchStatistics = new UserMatchStatisticsService({ * data: { userId: req.params.userId } * }); * * await userMatchStatistics.getDataByDependencyId(); * * res.send( * userMatchStatistics.data * ); * } * ] * }), * ]; * } * } */ export abstract class DyNTS_Controller extends DyNTS_SingletonService { /** * setup this in the setupEndpoints(), which will be called on the construcion * * @example * * this.endpoints = [ * new DyNTS_Endpoint_Params({ * name: 'getUserMatchStatistics', * type: DyFM_HttpCallType.get, * endpoint: '/get/user-match-statistics/:userId', * preProcesses: [ this.authService.authenticate_tokenSelf ], * tasks: [ * async (req: Request, res: Response) => { * const userMatchStatistics = new UserMatchStatisticsService({ * data: { userId: req.params.userId } * }); * * await userMatchStatistics.getDataByDependencyId(); * * res.send( * userMatchStatistics.data * ); * } * ] * }), * ]; */ endpoints: DyNTS_Endpoint_Params[]; /* protected constructor(){ super(); try { this.setupEndpoints(); } catch (error) { throw new DyFM_Error({ message: 'DynamoNTSController setup failed. Please check the setupEndpoints() method.', errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-COS-000', issuerService: this?.constructor?.name, error: error, level: DyFM_ErrorLevel.critical, }); } } */ /** * You must setup endpoints and required services in this function * * @example * * setupEndpoints(): void { * this.authService = AuthService.getInstance(); * * this.endpoints = [ * new DyNTS_Endpoint_Params({ * name: 'getUserMatchStatistics', * type: DyFM_HttpCallType.get, * endpoint: '/get/user-match-statistics/:userId', * preProcesses: [ this.authService.authenticate_tokenSelf ], * tasks: [ * async (req: Request, res: Response) => { * const userMatchStatistics = new UserMatchStatisticsService({ * data: { userId: req.params.userId } * }); * * await userMatchStatistics.getDataByDependencyId(); * * res.send( * userMatchStatistics.data * ); * } * ] * }), * ]; * } */ abstract setupEndpoints(): void }