Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

Commit

Permalink
feat: trash bin chart #33
Browse files Browse the repository at this point in the history
  • Loading branch information
NotHydra committed Mar 1, 2024
1 parent 75ae59c commit 806c524
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
21 changes: 20 additions & 1 deletion apps/api/src/model/trash-bin/trash-bin.controller.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -22,6 +22,25 @@ export class TrashBinController
super(TrashBinController.name, modelService);
}

@Get("chart")
public async getChart(): Promise<ResponseFormatInterface<number>> {
try {
const response: ResponseFormatInterface<number> = formatResponse<number>(
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<null>(false, 500, error.message, null);
}
}

@Put(":id/open-count/increase")
public async increaseOpenCount(
@Param("id", ParseIntPipe) id: number
Expand Down
13 changes: 13 additions & 0 deletions apps/api/src/model/trash-bin/trash-bin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ export class TrashBinService
});
}

public async getChart(): Promise<number> {
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<TrashBinModel> {
try {
const dataModel: { openCount: number } = await this.prismaService[this.modelName].findUnique({
Expand Down

0 comments on commit 806c524

Please sign in to comment.