feat: delete quotation endpoints

This commit is contained in:
Methapon2001 2024-07-23 16:14:39 +07:00
parent fbf7f6c968
commit c13eeb9b14

View file

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