feat: delete branch endpoint

This commit is contained in:
Methapon2001 2024-04-02 10:45:37 +07:00
parent 59a79a3374
commit 9938dba0e1

View file

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