feat: delete customer branch

This commit is contained in:
Methapon2001 2024-04-05 15:13:33 +07:00
parent 3f43ad1b9b
commit c0e59ccb70

View file

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