diff --git a/apps/api/src/model/trash-bin/trash-bin.controller.ts b/apps/api/src/model/trash-bin/trash-bin.controller.ts index e078414..a0a551b 100644 --- a/apps/api/src/model/trash-bin/trash-bin.controller.ts +++ b/apps/api/src/model/trash-bin/trash-bin.controller.ts @@ -1,4 +1,4 @@ -import { Controller, NotFoundException, Param, ParseIntPipe, Put, UseInterceptors } from "@nestjs/common"; +import { Controller, Get, NotFoundException, Param, ParseIntPipe, Put, UseInterceptors } from "@nestjs/common"; import { ResponseFormatInterface, TrashBinCreateDTO, TrashBinModel, TrashBinUpdateDTO } from "@trashtrack/common"; import { ResponseFormatInterceptor, formatResponse } from "../../interceptor/response-format.interceptor"; @@ -22,6 +22,25 @@ export class TrashBinController super(TrashBinController.name, modelService); } + @Get("chart") + public async getChart(): Promise> { + try { + const response: ResponseFormatInterface = formatResponse( + true, + 200, + "Chart Found", + await this.modelService.getChart() + ); + + this.loggerService.log(`Chart: ${JSON.stringify(response)}`); + + return response; + } catch (error) { + this.loggerService.error(`Chart: ${error.message}`); + return formatResponse(false, 500, error.message, null); + } + } + @Put(":id/open-count/increase") public async increaseOpenCount( @Param("id", ParseIntPipe) id: number diff --git a/apps/api/src/model/trash-bin/trash-bin.service.ts b/apps/api/src/model/trash-bin/trash-bin.service.ts index 06348d5..e21048f 100644 --- a/apps/api/src/model/trash-bin/trash-bin.service.ts +++ b/apps/api/src/model/trash-bin/trash-bin.service.ts @@ -22,6 +22,19 @@ export class TrashBinService }); } + public async getChart(): Promise { + try { + const data: number = await this.prismaService[this.modelName].count(); + + this.loggerService.log(`Chart: ${JSON.stringify(data)}`); + + return data; + } catch (error) { + this.loggerService.error(`Chart: ${error.message}`); + throw new InternalServerErrorException("Internal Server Error"); + } + } + public async increaseOpenCount(id: number): Promise { try { const dataModel: { openCount: number } = await this.prismaService[this.modelName].findUnique({