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 }, + }); + } }