mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-13 00:03:27 +10:00
fix: add logger for errors, return correct error when resume is locked
This commit is contained in:
@ -3,6 +3,7 @@ import {
|
||||
ForbiddenException,
|
||||
Injectable,
|
||||
InternalServerErrorException,
|
||||
Logger,
|
||||
} from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { JwtService } from "@nestjs/jwt";
|
||||
@ -115,6 +116,7 @@ export class AuthService {
|
||||
throw new BadRequestException(ErrorMessage.UserAlreadyExists);
|
||||
}
|
||||
|
||||
Logger.error(error);
|
||||
throw new InternalServerErrorException(error);
|
||||
}
|
||||
}
|
||||
@ -213,6 +215,7 @@ export class AuthService {
|
||||
|
||||
await this.mailService.sendEmail({ to: email, subject, text });
|
||||
} catch (error) {
|
||||
Logger.error(error);
|
||||
throw new InternalServerErrorException(error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,6 +55,7 @@ export class ResumeController {
|
||||
throw new BadRequestException(ErrorMessage.ResumeSlugAlreadyExists);
|
||||
}
|
||||
|
||||
Logger.error(error);
|
||||
throw new InternalServerErrorException(error);
|
||||
}
|
||||
}
|
||||
@ -69,6 +70,7 @@ export class ResumeController {
|
||||
throw new BadRequestException(ErrorMessage.ResumeSlugAlreadyExists);
|
||||
}
|
||||
|
||||
Logger.error(error);
|
||||
throw new InternalServerErrorException(error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,9 @@
|
||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
import {
|
||||
BadRequestException,
|
||||
Injectable,
|
||||
InternalServerErrorException,
|
||||
Logger,
|
||||
} from "@nestjs/common";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { CreateResumeDto, ImportResumeDto, ResumeDto, UpdateResumeDto } from "@reactive-resume/dto";
|
||||
import { defaultResumeData, ResumeData } from "@reactive-resume/schema";
|
||||
@ -127,6 +132,13 @@ export class ResumeService {
|
||||
|
||||
async update(userId: string, id: string, updateResumeDto: UpdateResumeDto) {
|
||||
try {
|
||||
const { locked } = await this.prisma.resume.findUniqueOrThrow({
|
||||
where: { id },
|
||||
select: { locked: true },
|
||||
});
|
||||
|
||||
if (locked) throw new BadRequestException(ErrorMessage.ResumeLocked);
|
||||
|
||||
const resume = await this.prisma.resume.update({
|
||||
data: {
|
||||
title: updateResumeDto.title,
|
||||
@ -134,7 +146,7 @@ export class ResumeService {
|
||||
visibility: updateResumeDto.visibility,
|
||||
data: updateResumeDto.data as unknown as Prisma.JsonObject,
|
||||
},
|
||||
where: { userId_id: { userId, id }, locked: false },
|
||||
where: { userId_id: { userId, id } },
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
@ -147,7 +159,8 @@ export class ResumeService {
|
||||
return resume;
|
||||
} catch (error) {
|
||||
if (error.code === "P2025") {
|
||||
throw new BadRequestException(ErrorMessage.ResumeLocked);
|
||||
Logger.error(error);
|
||||
throw new InternalServerErrorException(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import {
|
||||
Delete,
|
||||
Get,
|
||||
InternalServerErrorException,
|
||||
Logger,
|
||||
Patch,
|
||||
Res,
|
||||
UseGuards,
|
||||
@ -61,6 +62,7 @@ export class UserController {
|
||||
throw new BadRequestException(ErrorMessage.UserAlreadyExists);
|
||||
}
|
||||
|
||||
Logger.error(error);
|
||||
throw new InternalServerErrorException(error);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user