From 5649b40dd983402d3b96ba2474f0936d1e57fd8a Mon Sep 17 00:00:00 2001 From: elizielx Date: Sat, 17 Feb 2024 08:47:45 +0800 Subject: [PATCH] feat: add a new endpoint that exclude imageData due to perf issue on app --- .../api/src/model/report/report.controller.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/apps/api/src/model/report/report.controller.ts b/apps/api/src/model/report/report.controller.ts index 055e88b..db7e36c 100644 --- a/apps/api/src/model/report/report.controller.ts +++ b/apps/api/src/model/report/report.controller.ts @@ -89,6 +89,35 @@ export class ReportController } } + @Get("no-image") + public async findAllButNotWithImage(): Promise[]>> { + try { + const data: ReportModel[] = await this.modelService.find(); + + const simplifiedReportModels = data.map((report) => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { imageData, ...simplifiedReport } = report; + return simplifiedReport; + }); + + const response: ResponseFormatInterface[]> = formatResponse< + Omit[] + >(true, 200, "Found", simplifiedReportModels); + + this.loggerService.log(`Find All But Not With Image: ${JSON.stringify(response)}`); + + return response; + } catch (error) { + if (error instanceof NotFoundException) { + this.loggerService.error(`Find All But Not With Image: ${error.message}`); + return formatResponse(false, 404, error.message, null); + } + + this.loggerService.error(`Find All But Not With Image: ${error.message}`); + return formatResponse(false, 500, error.message, null); + } + } + @Override public async change( // eslint-disable-next-line @typescript-eslint/no-unused-vars