diff --git a/src/stores/customer/index.ts b/src/stores/customer/index.ts index d02573da..af58f361 100644 --- a/src/stores/customer/index.ts +++ b/src/stores/customer/index.ts @@ -254,24 +254,21 @@ const useCustomerStore = defineStore('api-customer', () => { const { customerBranch, image, ...payload } = data; - const res = await api.post< - Customer & { - branch: CustomerBranch[]; - imageUrl: string; - imageUploadUrl: string; - } - >('/customer', { - ...payload, - branch: data.customerBranch?.map((v) => ({ - ...v, - file: undefined, - branchCode: undefined, - id: undefined, - customerId: undefined, - codeCustomer: undefined, - })), - selectedImage: imgList.selectedImage, - }); + const res = await api.post( + '/customer', + { + ...payload, + branch: data.customerBranch?.map((v) => ({ + ...v, + file: undefined, + branchCode: undefined, + id: undefined, + customerId: undefined, + codeCustomer: undefined, + })), + selectedImage: imgList.selectedImage, + }, + ); if (imgList.list.length > 0 && res.data.id) { for (let index = 0; index < imgList.list.length; index++) { @@ -283,6 +280,29 @@ const useCustomerStore = defineStore('api-customer', () => { if (!res) return false; + await Promise.all( + res.data.branch.map(async (v, i) => { + const _citizen = customerBranch?.at(i)?.citizen; + + if (_citizen) { + for (let i = 0; i < _citizen.length; i++) { + const _res = await api.post<{ id: string }>( + `/customer-branch/${v.id}/citizen`, + _citizen[i], + ); + if (_res.data.id) { + await fileManager.putFile({ + group: 'citizen', + parentId: v.id, + file: _citizen[i].file, + fileId: _res.data.id, + }); + } + } + } + }), + ); + return res.data; } diff --git a/src/stores/customer/types.ts b/src/stores/customer/types.ts index 40e3744c..c3ca05a5 100644 --- a/src/stores/customer/types.ts +++ b/src/stores/customer/types.ts @@ -143,6 +143,7 @@ export type CustomerBranchCreate = { authorizedName?: string; authorizedNameEN?: string; code?: 'string'; + citizen?: CitizenPayload[]; file?: { name?: string; group?: string; @@ -199,3 +200,30 @@ export type CustomerStats = { CORP: number; PERS: number; }; + +export type CitizenPayload = { + namePrefix?: string; + firstName: string; + firstNameEN?: string; + middleName?: string; + middleNameEN?: string; + lastName: string; + lastNameEN?: string; + issueDate: Date; + expireDate: Date; + nationality: string; + religion: string; + gender: string; + address?: string; + addressEN?: string; + soi?: string; + soiEN?: string; + moo?: string; + mooEN?: string; + street?: string; + streetEN?: string; + provinceId?: string; + districtId?: string; + subDistrictId?: string; + file: File; +};