From 03d25219c11bc4b0c490043ef3c2094e7bd7e821 Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Thu, 22 Aug 2024 14:29:18 +0700 Subject: [PATCH] feat: update status of headoffice so it cannot be delete --- src/controllers/customer-branch-controller.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/controllers/customer-branch-controller.ts b/src/controllers/customer-branch-controller.ts index 9dfa0a6..c79502b 100644 --- a/src/controllers/customer-branch-controller.ts +++ b/src/controllers/customer-branch-controller.ts @@ -333,7 +333,8 @@ export class CustomerBranchController extends Controller { const record = await prisma.$transaction( async (tx) => { - const headofficeCode = customer.branch.at(0)?.code.slice(0, -3); + const headoffice = customer.branch.at(0); + const headofficeCode = headoffice?.code.slice(0, -3); let runningKey = ""; @@ -354,6 +355,16 @@ export class CustomerBranchController extends Controller { update: { value: { increment: 1 } }, }); + if (headoffice) { + await tx.customerBranch.updateMany({ + where: { + id: headoffice.id, + status: "CREATED", + }, + data: { status: "ACTIVE" }, + }); + } + return await tx.customerBranch.create({ include: { province: true,