From 011d53d65572cfcc7ef205efe0cfd743aecab698 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Fri, 5 Apr 2024 14:43:21 +0700 Subject: [PATCH] fix: error on not exist --- src/controllers/customer-branch-controller.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/controllers/customer-branch-controller.ts b/src/controllers/customer-branch-controller.ts index 642d63d..4312eb6 100644 --- a/src/controllers/customer-branch-controller.ts +++ b/src/controllers/customer-branch-controller.ts @@ -194,6 +194,10 @@ export class CustomerBranchController extends Controller { const { provinceId, districtId, subDistrictId, customerId, ...rest } = body; + if (!(await prisma.customerBranch.findUnique({ where: { id: branchId } }))) { + throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "data_not_found"); + } + const record = await prisma.customerBranch.update({ where: { id: branchId }, include: {