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,
|
CitizenPayload,
|
||||||
} from './types';
|
} from './types';
|
||||||
import { Employee } from '../employee/types';
|
import { Employee } from '../employee/types';
|
||||||
import { baseUrl, manageFile } from '../utils';
|
import { baseUrl, manageFile, manageMeta } from '../utils';
|
||||||
|
|
||||||
const useCustomerStore = defineStore('api-customer', () => {
|
const useCustomerStore = defineStore('api-customer', () => {
|
||||||
const data = ref<Pagination<Customer[]>>();
|
const data = ref<Pagination<Customer[]>>();
|
||||||
|
|
@ -26,6 +26,14 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
| 'power-of-attorney'
|
| 'power-of-attorney'
|
||||||
>(api, 'customer-branch');
|
>(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) {
|
async function setImage(id: string, image: File) {
|
||||||
await api.put(`/customer/${id}/image`, image, {
|
await api.put(`/customer/${id}/image`, image, {
|
||||||
headers: { 'Content-Type': image?.type },
|
headers: { 'Content-Type': image?.type },
|
||||||
|
|
@ -285,23 +293,24 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
res.data.branch.map(async (v, i) => {
|
res.data.branch.map(async (v, i) => {
|
||||||
const _citizen = customerBranch?.at(i)?.citizen;
|
const tempValue = customerBranch?.at(i);
|
||||||
|
|
||||||
if (_citizen) {
|
if (tempValue) {
|
||||||
for (let i = 0; i < _citizen.length; i++) {
|
tempValue.file?.forEach(async ({ group, _meta, file }) => {
|
||||||
const _res = await api.post<{ id: string }>(
|
if (file !== undefined) {
|
||||||
`/customer-branch/${v.id}/citizen`,
|
await metaManager.postMeta({
|
||||||
_citizen[i],
|
|
||||||
);
|
|
||||||
if (_res.data.id) {
|
|
||||||
await fileManager.putFile({
|
|
||||||
group: 'citizen',
|
|
||||||
parentId: v.id,
|
parentId: v.id,
|
||||||
file: _citizen[i].file,
|
group: group as
|
||||||
fileId: _res.data.id,
|
| 'citizen'
|
||||||
|
| 'house-registration'
|
||||||
|
| 'commercial-registration'
|
||||||
|
| 'vat-registration'
|
||||||
|
| 'power-of-attorney',
|
||||||
|
meta: _meta,
|
||||||
|
file,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
@ -518,6 +527,7 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
deleteAttachment,
|
deleteAttachment,
|
||||||
|
|
||||||
...fileManager,
|
...fileManager,
|
||||||
|
...metaManager,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue