refactor: add metaManager
This commit is contained in:
parent
eedbd2699c
commit
95671b7056
1 changed files with 24 additions and 14 deletions
|
|
@ -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<Pagination<Customer[]>>();
|
||||
|
|
@ -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,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue