From fe3532eabdaa3f1604460b5e89042b597ef4783e Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Tue, 17 Sep 2024 13:37:02 +0700 Subject: [PATCH] feat: create citizenId relation --- src/stores/customer/index.ts | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/stores/customer/index.ts b/src/stores/customer/index.ts index af58f361..55c75063 100644 --- a/src/stores/customer/index.ts +++ b/src/stores/customer/index.ts @@ -10,6 +10,7 @@ import { CustomerBranch, CustomerBranchCreate, CustomerType, + CitizenPayload, } from './types'; import { Employee } from '../employee/types'; import { baseUrl, manageFile } from '../utils'; @@ -312,8 +313,6 @@ const useCustomerStore = defineStore('api-customer', () => { const res = await api.put< Customer & { branch: CustomerBranch[]; - imageUrl: string; - imageUploadUrl: string; } >(`/customer/${id}`, { ...payload, @@ -360,8 +359,15 @@ const useCustomerStore = defineStore('api-customer', () => { codeCustomer: string; }, ) { - const { codeCustomer, statusSave, code, file, birthDate, ...payload } = - data; + const { + codeCustomer, + statusSave, + code, + file, + birthDate, + citizen, + ...payload + } = data; if (data.citizenId) { delete data['authorizedNameEN']; @@ -383,6 +389,23 @@ const useCustomerStore = defineStore('api-customer', () => { const res = await api.post('/customer-branch', payload); if (!res) return false; + if (citizen) { + for (let i = 0; i < citizen.length; i++) { + const _res = await api.post<{ id: string }>( + `/customer-branch/${res.data.id}/citizen`, + citizen[i], + ); + if (_res.data.id) { + await fileManager.putFile({ + group: 'citizen', + parentId: res.data.id, + file: citizen[i].file, + fileId: _res.data.id, + }); + } + } + } + return res.data; }