From deb50dc65d7eb5fbf3a88281bfaf433d3847ec3b Mon Sep 17 00:00:00 2001 From: Thanaphon Frappet Date: Tue, 12 Nov 2024 16:05:05 +0700 Subject: [PATCH] refactor: handle attachment customer --- .../employer/EmployerFormBranch.vue | 127 ++++++++++++------ 1 file changed, 84 insertions(+), 43 deletions(-) diff --git a/src/pages/03_customer-management/components/employer/EmployerFormBranch.vue b/src/pages/03_customer-management/components/employer/EmployerFormBranch.vue index bd2c6655..186d5fb3 100644 --- a/src/pages/03_customer-management/components/employer/EmployerFormBranch.vue +++ b/src/pages/03_customer-management/components/employer/EmployerFormBranch.vue @@ -15,6 +15,7 @@ import { import useOcrStore from 'stores/ocr'; import useCustomerStore from 'stores/customer'; +import { dateFormat } from 'src/utils/datetime'; import { SaveButton, @@ -24,6 +25,8 @@ import { } from 'components/button'; import { UploadFileGroup } from 'src/components/upload-file/'; import { uploadFileListCustomer, columnsAttachment } from '../../constant'; +import { symOutlinedResume } from '@quasar/extras/material-symbols-outlined'; +import { group } from 'console'; const ocrStore = useOcrStore(); const customerStore = useCustomerStore(); @@ -219,21 +222,24 @@ withDefaults( hide-action :ocr=" async (group, file) => { - const res = await ocrStore.sendOcr({ - file: file, - category: group, - }); + console.log(group); + if (group !== 'attachment') { + const res = await ocrStore.sendOcr({ + file: file, + category: group, + }); - if (res) { - const tempValue = { - status: true, - group, - meta: res.fields, - }; + if (res) { + const tempValue = { + status: true, + group, + meta: res.fields, + }; - return tempValue; + return tempValue; + } } - return { status: false, group, meta: [] }; + return { status: true, group, meta: [] }; } " :menu="uploadFileListCustomer" @@ -270,41 +276,54 @@ withDefaults( | 'house-registration' | 'commercial-registration' | 'vat-registration' - | 'power-of-attorney', + | 'power-of-attorney' + | 'attachment', _meta: any, file: File | undefined, ) => { - if (file !== undefined && item.id) { - const res = await customerStore.postMeta({ - parentId: item.id || '', - group, - meta: _meta, - file, - }); + if (group !== 'attachment') { + if (file !== undefined && item.id) { + const res = await customerStore.postMeta({ + parentId: item.id || '', + group, + meta: _meta, + file, + }); - if (res) { - return true; + if (res) { + 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 { - const { - customerBranchId, - id, - employeeId, - createdAt, - updatedAt, - middleName, - middleNameEN, + if (file !== undefined) { + await customerStore.putAttachment({ + parentId: item.id || '', + name: file.name, + file: file, + }); - ...payload - } = _meta; - const res = await customerStore.putMeta({ - parentId: item.id || '', - group, - metaId: _meta.id, - meta: payload, - file, - }); - if (res) { return true; } } @@ -319,19 +338,21 @@ withDefaults( | 'house-registration' | 'commercial-registration' | 'vat-registration' - | 'power-of-attorney', + | 'power-of-attorney' + | 'attachment', ) => { if (!!item.id) { - if (group === 'citizen') { + if (group !== 'attachment') { const resMeta = await customerStore.getMetaList({ parentId: item.id, group, }); const tempValue = resMeta.map(async (v: any) => { + console.log(v.expireDate); return { _meta: { ...v }, - name: v.id || '', + name: `${group}-${dateFormat(v.expireDate)}`, group: group, url: await customerStore.getFile({ 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); } }