From 9938dba0e1d7587bd8a8d7285f3fa7142571cb61 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 2 Apr 2024 10:45:37 +0700 Subject: [PATCH] feat: delete branch endpoint --- src/controllers/branch/branch-controller.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/controllers/branch/branch-controller.ts b/src/controllers/branch/branch-controller.ts index 7f8c448..99e78b2 100644 --- a/src/controllers/branch/branch-controller.ts +++ b/src/controllers/branch/branch-controller.ts @@ -65,4 +65,19 @@ export class BranchController extends Controller { where: { id: branchId }, }); } + + @Delete("{branchId}") + async deleteBranch(@Path() branchId: string) { + const record = await prisma.branch.findFirst({ where: { id: branchId } }); + + if (!record) { + throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found."); + } + + if (record.status === Status.USED) { + throw new HttpError(HttpStatus.FORBIDDEN, "Branch is in used."); + } + + return await prisma.branch.delete({ where: { id: branchId } }); + } }