import { Request, Response } from 'express'; import { DyFM_HttpCallType } from '@futdevpro/fsm-dynamo'; import { DyFM_customDataModule_settings } from '@futdevpro/fsm-dynamo/custom-data'; import { DyNTS_Endpoint_Params } from '../../_models/control-models/endpoint-params.control-model'; import { DyNTS_Controller } from '../../_services/route/controller.service'; import { DyNTS_CustomData_DataService } from './custom-data.data-service'; export class DyNTS_CustomData_Controller extends DyNTS_Controller { static getInstance(): DyNTS_CustomData_Controller { return DyNTS_CustomData_Controller.getSingletonInstance(); } setupEndpoints(): void { this.endpoints = [ // CUSTOM DATA new DyNTS_Endpoint_Params({ name: 'getCustomData', type: DyFM_HttpCallType.get, endpoint: DyFM_customDataModule_settings.endPoints.getCustomData, tasks: [ async (req: Request, res: Response): Promise => { const customDataService = new DyNTS_CustomData_DataService({ _id: req.params.customId, }); await customDataService.getDataById(); res.send({ url: req.url, result: 'get custom call was successful!', response: customDataService.data, request: `.../custom/get/${req.params.customId}`, }); }, ], }), new DyNTS_Endpoint_Params({ name: 'modifyCustomData', type: DyFM_HttpCallType.post, endpoint: DyFM_customDataModule_settings.endPoints.modifyCustomData, tasks: [ async (req: Request, res: Response, issuer: string): Promise => { const customDataService = new DyNTS_CustomData_DataService(req.body, issuer); res.send({ url: req.url, result: 'post custom call was successful!', response: await customDataService.saveData(req.body), warning: 'keep in mind that this is a playground DB, ' + 'and it will be cleared out from time to time', request: req.body, }); }, ], }), ]; } }