From c13eeb9b1459e759c23039340f132f304ccf6905 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 23 Jul 2024 16:14:39 +0700 Subject: [PATCH] feat: delete quotation endpoints --- src/controllers/quotation-controller.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/controllers/quotation-controller.ts b/src/controllers/quotation-controller.ts index f586168..628d259 100644 --- a/src/controllers/quotation-controller.ts +++ b/src/controllers/quotation-controller.ts @@ -496,5 +496,25 @@ export class QuotationController extends Controller { @Delete("{quotationId}") @Security("keycloak") - async deleteQuotationById(@Request() req: RequestWithUser, @Path() quotationId: string) {} + async deleteQuotationById(@Request() req: RequestWithUser, @Path() quotationId: string) { + const record = await prisma.quotation.findUnique({ + where: { id: quotationId }, + }); + + if (!record) { + throw new HttpError(HttpStatus.NOT_FOUND, "Quotation not found.", "quotationNotFound"); + } + + if (record.status !== Status.CREATED) { + throw new HttpError(HttpStatus.FORBIDDEN, "Quotation is in used.", "quotationInUsed"); + } + + return await prisma.quotation.delete({ + include: { + createdBy: true, + updatedBy: true, + }, + where: { id: quotationId }, + }); + } }