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