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