refactor: handle attachment customer

This commit is contained in:
Thanaphon Frappet 2024-11-12 16:05:05 +07:00
parent 44a74fd64a
commit deb50dc65d

View file

@ -15,6 +15,7 @@ import {
import useOcrStore from 'stores/ocr'; import useOcrStore from 'stores/ocr';
import useCustomerStore from 'stores/customer'; import useCustomerStore from 'stores/customer';
import { dateFormat } from 'src/utils/datetime';
import { import {
SaveButton, SaveButton,
@ -24,6 +25,8 @@ import {
} from 'components/button'; } from 'components/button';
import { UploadFileGroup } from 'src/components/upload-file/'; import { UploadFileGroup } from 'src/components/upload-file/';
import { uploadFileListCustomer, columnsAttachment } from '../../constant'; import { uploadFileListCustomer, columnsAttachment } from '../../constant';
import { symOutlinedResume } from '@quasar/extras/material-symbols-outlined';
import { group } from 'console';
const ocrStore = useOcrStore(); const ocrStore = useOcrStore();
const customerStore = useCustomerStore(); const customerStore = useCustomerStore();
@ -219,21 +222,24 @@ withDefaults(
hide-action hide-action
:ocr=" :ocr="
async (group, file) => { async (group, file) => {
const res = await ocrStore.sendOcr({ console.log(group);
file: file, if (group !== 'attachment') {
category: group, const res = await ocrStore.sendOcr({
}); file: file,
category: group,
});
if (res) { if (res) {
const tempValue = { const tempValue = {
status: true, status: true,
group, group,
meta: res.fields, meta: res.fields,
}; };
return tempValue; return tempValue;
}
} }
return { status: false, group, meta: [] }; return { status: true, group, meta: [] };
} }
" "
:menu="uploadFileListCustomer" :menu="uploadFileListCustomer"
@ -270,41 +276,54 @@ withDefaults(
| 'house-registration' | 'house-registration'
| 'commercial-registration' | 'commercial-registration'
| 'vat-registration' | 'vat-registration'
| 'power-of-attorney', | 'power-of-attorney'
| 'attachment',
_meta: any, _meta: any,
file: File | undefined, file: File | undefined,
) => { ) => {
if (file !== undefined && item.id) { if (group !== 'attachment') {
const res = await customerStore.postMeta({ if (file !== undefined && item.id) {
parentId: item.id || '', const res = await customerStore.postMeta({
group, parentId: item.id || '',
meta: _meta, group,
file, meta: _meta,
}); file,
});
if (res) { if (res) {
return true; return true;
}
} else {
const {
customerBranchId,
id,
employeeId,
createdAt,
updatedAt,
middleName,
middleNameEN,
...payload
} = _meta;
const res = await customerStore.putMeta({
parentId: item.id || '',
group,
metaId: _meta.id,
meta: payload,
file,
});
if (res) {
return true;
}
} }
} else { } else {
const { if (file !== undefined) {
customerBranchId, await customerStore.putAttachment({
id, parentId: item.id || '',
employeeId, name: file.name,
createdAt, file: file,
updatedAt, });
middleName,
middleNameEN,
...payload
} = _meta;
const res = await customerStore.putMeta({
parentId: item.id || '',
group,
metaId: _meta.id,
meta: payload,
file,
});
if (res) {
return true; return true;
} }
} }
@ -319,19 +338,21 @@ withDefaults(
| 'house-registration' | 'house-registration'
| 'commercial-registration' | 'commercial-registration'
| 'vat-registration' | 'vat-registration'
| 'power-of-attorney', | 'power-of-attorney'
| 'attachment',
) => { ) => {
if (!!item.id) { if (!!item.id) {
if (group === 'citizen') { if (group !== 'attachment') {
const resMeta = await customerStore.getMetaList({ const resMeta = await customerStore.getMetaList({
parentId: item.id, parentId: item.id,
group, group,
}); });
const tempValue = resMeta.map(async (v: any) => { const tempValue = resMeta.map(async (v: any) => {
console.log(v.expireDate);
return { return {
_meta: { ...v }, _meta: { ...v },
name: v.id || '', name: `${group}-${dateFormat(v.expireDate)}`,
group: group, group: group,
url: await customerStore.getFile({ url: await customerStore.getFile({
parentId: item.id || '', parentId: item.id || '',
@ -342,6 +363,26 @@ withDefaults(
}; };
}); });
return await waitAll(tempValue);
} else {
const res = await customerStore.listAttachment({
parentId: item.id || '',
});
const tempValue = (res as string[]).map(async (i: any) => {
console.log(i);
return {
_meta: { id: i, name: i },
name: i || '',
group: group,
url: await customerStore.getAttachment({
parentId: item.id || '',
name: i,
}),
file: undefined,
};
});
return await waitAll(tempValue); return await waitAll(tempValue);
} }
} }