diff --git a/src/stores/customer/index.ts b/src/stores/customer/index.ts index e5b83cfb..31044c22 100644 --- a/src/stores/customer/index.ts +++ b/src/stores/customer/index.ts @@ -13,7 +13,7 @@ import { CitizenPayload, } from './types'; import { Employee } from '../employee/types'; -import { baseUrl, manageFile } from '../utils'; +import { baseUrl, manageFile, manageMeta } from '../utils'; const useCustomerStore = defineStore('api-customer', () => { const data = ref>(); @@ -26,6 +26,14 @@ const useCustomerStore = defineStore('api-customer', () => { | 'power-of-attorney' >(api, 'customer-branch'); + const metaManager = manageMeta< + | 'citizen' + | 'house-registration' + | 'commercial-registration' + | 'vat-registration' + | 'power-of-attorney' + >(api, 'customer-branch'); + async function setImage(id: string, image: File) { await api.put(`/customer/${id}/image`, image, { headers: { 'Content-Type': image?.type }, @@ -285,23 +293,24 @@ const useCustomerStore = defineStore('api-customer', () => { await Promise.all( res.data.branch.map(async (v, i) => { - const _citizen = customerBranch?.at(i)?.citizen; + const tempValue = customerBranch?.at(i); - 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', + if (tempValue) { + tempValue.file?.forEach(async ({ group, _meta, file }) => { + if (file !== undefined) { + await metaManager.postMeta({ parentId: v.id, - file: _citizen[i].file, - fileId: _res.data.id, + group: group as + | 'citizen' + | 'house-registration' + | 'commercial-registration' + | 'vat-registration' + | 'power-of-attorney', + meta: _meta, + file, }); } - } + }); } }), ); @@ -518,6 +527,7 @@ const useCustomerStore = defineStore('api-customer', () => { deleteAttachment, ...fileManager, + ...metaManager, }; });