From 2ae0824fa9770c16f51905f54c7a6ebe1a972419 Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Mon, 16 Sep 2024 14:14:53 +0700 Subject: [PATCH] Revert "refactor: combine payload" This reverts commit c7b5f91d31df63cadebfb91fd09e45f1f5feb90a. --- src/controllers/03-customer-controller.ts | 37 ++++++++++++----------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/controllers/03-customer-controller.ts b/src/controllers/03-customer-controller.ts index 367cd91..b33d87b 100644 --- a/src/controllers/03-customer-controller.ts +++ b/src/controllers/03-customer-controller.ts @@ -51,21 +51,24 @@ export type CustomerCreate = { status?: Status; selectedImage?: string; - branch: { - // NOTE: About (Natural Person) - citizenId: string; - - // NOTE: About (Legal Entity) - legalPersonNo?: string; - registerName?: string; - registerNameEN?: string; - registerDate?: Date; - authorizedCapital?: string; - authorizedName?: string; - authorizedNameEN?: string; - customerName?: string; - - customerId?: string; + branch: (( + | { + // NOTE: About (Natural Person) + citizenId: string; + } + | { + // NOTE: About (Legal Entity) + legalPersonNo: string; + registerName: string; + registerNameEN: string; + registerDate: Date; + authorizedCapital: string; + authorizedName: string; + authorizedNameEN: string; + } + ) & { + customerId: string; + customerName: string; telephoneNo: string; @@ -100,7 +103,7 @@ export type CustomerCreate = { subDistrictId?: string | null; districtId?: string | null; provinceId?: string | null; - }[]; + })[]; }; export type CustomerUpdate = { @@ -264,7 +267,7 @@ export class CustomerController extends Controller { ); } - const runningKey = `CUSTOMER_BRANCH_${company}_${headoffice.citizenId || headoffice.legalPersonNo}`; + const runningKey = `CUSTOMER_BRANCH_${company}_${"citizenId" in headoffice ? headoffice.citizenId : headoffice.legalPersonNo}`; const last = await tx.runningNo.upsert({ where: { key: runningKey },