fix: error when record not found on update
This commit is contained in:
parent
7d26d6a9ea
commit
6899c9823a
2 changed files with 23 additions and 7 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue