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,6 +222,8 @@ withDefaults(
hide-action hide-action
:ocr=" :ocr="
async (group, file) => { async (group, file) => {
console.log(group);
if (group !== 'attachment') {
const res = await ocrStore.sendOcr({ const res = await ocrStore.sendOcr({
file: file, file: file,
category: group, category: group,
@ -233,7 +238,8 @@ withDefaults(
return tempValue; return tempValue;
} }
return { status: false, group, meta: [] }; }
return { status: true, group, meta: [] };
} }
" "
:menu="uploadFileListCustomer" :menu="uploadFileListCustomer"
@ -270,10 +276,12 @@ 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 (group !== 'attachment') {
if (file !== undefined && item.id) { if (file !== undefined && item.id) {
const res = await customerStore.postMeta({ const res = await customerStore.postMeta({
parentId: item.id || '', parentId: item.id || '',
@ -308,6 +316,17 @@ withDefaults(
return true; return true;
} }
} }
} else {
if (file !== undefined) {
await customerStore.putAttachment({
parentId: item.id || '',
name: file.name,
file: file,
});
return true;
}
}
return false; return false;
} }
@ -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);
} }
} }