From 6e07e0658eb6d0309d3fb4d419214ab188e69109 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Fri, 5 Apr 2024 11:02:23 +0700 Subject: [PATCH] feat: delete customer --- src/controllers/customer-controller.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/controllers/customer-controller.ts b/src/controllers/customer-controller.ts index 74748bf..e11957c 100644 --- a/src/controllers/customer-controller.ts +++ b/src/controllers/customer-controller.ts @@ -115,4 +115,19 @@ export class CustomerController extends Controller { ), }); } + + @Delete("{customerId}") + async deleteById(@Path() customerId: string) { + const record = await prisma.customer.findFirst({ where: { id: customerId } }); + + if (!record) { + throw new HttpError(HttpStatus.NOT_FOUND, "Customer cannot be found.", "data_not_found"); + } + + if (record.status !== Status.CREATED) { + throw new HttpError(HttpStatus.FORBIDDEN, "Customer is in used.", "data_in_used"); + } + + return await prisma.customer.delete({ where: { id: customerId } }); + } }