From c7f7713cbd1e2d55a9f877bd667e760fe1c4fe18 Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Tue, 20 Aug 2024 17:35:43 +0700 Subject: [PATCH] feat: also consider code from head office --- src/controllers/customer-branch-controller.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/controllers/customer-branch-controller.ts b/src/controllers/customer-branch-controller.ts index d4957b5..e6d898d 100644 --- a/src/controllers/customer-branch-controller.ts +++ b/src/controllers/customer-branch-controller.ts @@ -316,9 +316,13 @@ export class CustomerBranchController extends Controller { const record = await prisma.$transaction( async (tx) => { + const headofficeCode = customer.branch.at(0)?.code.slice(0, -3); + let runningKey = ""; - if ("citizenId" in body) { + if (headofficeCode) { + runningKey = `CUSTOMER_BRANCH_${headofficeCode}`; + } else if ("citizenId" in body) { runningKey = `CUSTOMER_BRANCH_${body.citizenId}`; } else { runningKey = `CUSTOMER_BRANCH_${body.legalPersonNo}`;