Skip to content

Commit

Permalink
refactor: Update PlanService to handle user not found in getPlan method
Browse files Browse the repository at this point in the history
  • Loading branch information
PleBea committed Jul 19, 2024
1 parent d7e2649 commit 0a1666e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 10 additions & 2 deletions src/modules/plan/plan.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ export class PlanService {
private readonly configService: ConfigService,
) {}

async getPlan(user: User): Promise<PlanResponseDTO> {
async getPlan({ id }: User): Promise<PlanResponseDTO> {
const user = await this.prisma.user.findUnique({
where: {
id: id,
},
});

if (!user) throw new HttpException('User not found', HttpStatus.NOT_FOUND);

const plan = await this.prisma.plan.findFirst({
where: {
users: {
Expand Down Expand Up @@ -100,7 +108,7 @@ export class PlanService {
}

async createPlan({ id }: User, dto: CreatePlanDTO) {
if (DateTime.fromISO(dto.date).diffNow('minutes').minutes >= -30)
if (DateTime.fromISO(dto.date).diffNow('minutes').minutes <= -30)
throw new HttpException('Invalid date', HttpStatus.BAD_REQUEST);

const user = await this.prisma.user.findUnique({
Expand Down
8 changes: 2 additions & 6 deletions src/modules/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,7 @@ export class UserController {
@ApiOkResponse({ description: 'User deleted', type: ResponseDTO<null> })
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
async deleteUser(@CurrentUser() user: User) {
try {
await this.userService.deleteUserById(user.id);
return { status: 'success', data: null };
} catch (error) {
return { status: 'error', data: null };
}
await this.userService.deleteUserById(user.id);
return { status: 'success', data: null };
}
}

0 comments on commit 0a1666e

Please sign in to comment.