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