From e7568fa06f7fb4ffd47fa5ad504a4ef938075a3f Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 3 Apr 2024 12:49:20 +0700 Subject: [PATCH] fix: update condition and response relation --- src/controllers/branch/branch-controller.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/controllers/branch/branch-controller.ts b/src/controllers/branch/branch-controller.ts index a255e56..3dac955 100644 --- a/src/controllers/branch/branch-controller.ts +++ b/src/controllers/branch/branch-controller.ts @@ -216,7 +216,7 @@ export class BranchController extends Controller { include: { province: true, district: true, subDistrict: true }, data: { ...rest, - isHeadOffice: headOfficeId === null, + isHeadOffice: headOfficeId !== undefined ? headOfficeId === null : undefined, province: { connect: provinceId ? { id: provinceId } : undefined, disconnect: provinceId === null || undefined, @@ -262,6 +262,13 @@ export class BranchController extends Controller { throw new HttpError(HttpStatus.FORBIDDEN, "Branch is in used.", "data_exists"); } - return await prisma.branch.delete({ where: { id: branchId } }); + return await prisma.branch.delete({ + include: { + province: true, + district: true, + subDistrict: true, + }, + where: { id: branchId }, + }); } }