fix: error when record not found on update

This commit is contained in:
Methapon2001 2024-04-05 15:23:59 +07:00
parent 7d26d6a9ea
commit 6899c9823a
2 changed files with 23 additions and 7 deletions

View file

@ -259,6 +259,10 @@ export class BranchController extends Controller {
const { provinceId, districtId, subDistrictId, headOfficeId, ...rest } = body;
if (!(await prisma.branch.findUnique({ where: { id: branchId } }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "data_not_found");
}
const record = await prisma.branch.update({
include: { province: true, district: true, subDistrict: true },
data: {
@ -284,9 +288,7 @@ export class BranchController extends Controller {
},
where: { id: branchId },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "data_not_found");
}
return record;
}