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

Commit

Permalink
chore: add override
Browse files Browse the repository at this point in the history
  • Loading branch information
NotHydra committed Feb 13, 2024
1 parent 0fe5d60 commit 6fd4932
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 27 deletions.
3 changes: 2 additions & 1 deletion apps/api/src/model/feedback/feedback.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Body, Controller, ForbiddenException, Param, ParseIntPipe, UseInterceptors } from "@nestjs/common";
import { FeedbackCreateDTO, FeedbackModel, FeedbackUpdateDTO, ResponseFormatInterface } from "@trashtrack/common";
import { FeedbackCreateDTO, FeedbackModel, FeedbackUpdateDTO, Override, ResponseFormatInterface } from "@trashtrack/common";

import { ResponseFormatInterceptor } from "../../interceptor/response-format.interceptor";

Expand All @@ -19,6 +19,7 @@ export class FeedbackController
super(FeedbackController.name, modelService);
}

@Override
public async change(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@Param("id", ParseIntPipe) id: number,
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/model/global/base.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class BaseController<
await this.modelService.add(payload)
);

this.loggerService.log(`Add: Added`);
this.loggerService.log(`Add: ${JSON.stringify(response)}`);

return response;
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/model/history/history.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Body, Controller, ForbiddenException, Param, ParseIntPipe, UseInterceptors } from "@nestjs/common";
import { HistoryCreateDTO, HistoryModel, HistoryUpdateDTO, ResponseFormatInterface } from "@trashtrack/common";
import { HistoryCreateDTO, HistoryModel, HistoryUpdateDTO, Override, ResponseFormatInterface } from "@trashtrack/common";

import { ResponseFormatInterceptor } from "../../interceptor/response-format.interceptor";

Expand All @@ -19,6 +19,7 @@ export class HistoryController
super(HistoryController.name, modelService);
}

@Override
public async change(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@Param("id", ParseIntPipe) id: number,
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/model/trash/trash.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Body, Controller, ForbiddenException, Param, ParseIntPipe, UseInterceptors } from "@nestjs/common";
import { ResponseFormatInterface, TrashCreateDTO, TrashModel, TrashUpdateDTO } from "@trashtrack/common";
import { Override, ResponseFormatInterface, TrashCreateDTO, TrashModel, TrashUpdateDTO } from "@trashtrack/common";

import { ResponseFormatInterceptor } from "../../interceptor/response-format.interceptor";

Expand All @@ -19,6 +19,7 @@ export class TrashController
super(TrashController.name, modelService);
}

@Override
public async change(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@Param("id", ParseIntPipe) id: number,
Expand Down
46 changes: 23 additions & 23 deletions apps/api/src/model/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ export class UserService extends BaseService<UserModel, UserCreateDTO, UserUpdat
}
}

public async comparePassword(username: string, password: string): Promise<boolean> {
try {
const model: { password: string } = await this.prismaService[this.modelName].findUnique({
where: { username },
select: { password: true },
});

if (!model) {
throw new NotFoundException(`Username ${username} Not Found`);
}

return await encryption.compare(password, model.password);
} catch (error) {
if (error instanceof PrismaClientKnownRequestError) {
this.loggerService.error(`Compare Password: Username ${username} Not Found`);
throw new NotFoundException(`Id ${username} Not Found`);
}

this.loggerService.error(`Compare Password: ${error.message}`);
throw new InternalServerErrorException("Internal Server Error");
}
}

@Override
public async add(payload: UserCreateDTO): Promise<UserModel> {
try {
Expand Down Expand Up @@ -122,29 +145,6 @@ export class UserService extends BaseService<UserModel, UserCreateDTO, UserUpdat
return super.change(id, payload);
}

public async comparePassword(username: string, password: string): Promise<boolean> {
try {
const model: { password: string } = await this.prismaService[this.modelName].findUnique({
where: { username },
select: { password: true },
});

if (!model) {
throw new NotFoundException(`Username ${username} Not Found`);
}

return await encryption.compare(password, model.password);
} catch (error) {
if (error instanceof PrismaClientKnownRequestError) {
this.loggerService.error(`Compare Password: Username ${username} Not Found`);
throw new NotFoundException(`Id ${username} Not Found`);
}

this.loggerService.error(`Compare Password: ${error.message}`);
throw new InternalServerErrorException("Internal Server Error");
}
}

public async changePassword(id: number, payload: UserUpdatePasswordDTO): Promise<UserModel> {
try {
if (payload.newPassword.length < 8) {
Expand Down

0 comments on commit 6fd4932

Please sign in to comment.