diff --git a/src/stores/employee/index.ts b/src/stores/employee/index.ts index e77274fb..8266b2b5 100644 --- a/src/stores/employee/index.ts +++ b/src/stores/employee/index.ts @@ -15,12 +15,13 @@ import { EmployeeVisaPayload, } from './types'; import { CustomerBranch } from '../customer/types'; -import { baseUrl, manageFile, manageMeta } from '../utils'; +import { baseUrl, manageAttachment, manageFile, manageMeta } from '../utils'; const useEmployeeStore = defineStore('api-employee', () => { const data = ref>(); const globalOption = ref(); const ownerOption = ref(); + const attachmentManager = manageAttachment(api, 'employee'); const fileManager = manageFile<'passport' | 'visa'>(api, 'employee'); const metaManager = manageMeta<'passport' | 'visa'>(api, 'employee'); @@ -118,13 +119,21 @@ const useEmployeeStore = defineStore('api-employee', () => { if (_ext) filename = filename + '.' + _ext; - if (group !== undefined && _meta !== undefined) { + if (group === undefined) return; + + if (group !== 'attachment' && _meta !== undefined) { metaManager.postMeta({ parentId: res.data.id, - group: group as 'passport' | 'visa' | 'in-country-notice', + group: group as 'passport' | 'visa', meta: _meta, file, }); + } else { + attachmentManager.putAttachment({ + parentId: res.data.id, + name: file.name, + file, + }); } } }); @@ -384,6 +393,7 @@ const useEmployeeStore = defineStore('api-employee', () => { const res = await api.get(`/employee/${employeeId}/attachment`); return !res || res.status >= 400 ? false : res.data; } + async function getAttachment( employeeId: string, filename: string, @@ -411,11 +421,11 @@ const useEmployeeStore = defineStore('api-employee', () => { file: File, filename?: string, ) { - const res = await api.put( - `/employee/${employeeId}/attachment/${filename || file.name}`, + await attachmentManager.putAttachment({ + parentId: employeeId, file, - ); - return !(!res || res.status >= 400); + name: filename || file.name, + }); } async function deleteAttachment(employeeId: string, filename: string) { @@ -478,14 +488,14 @@ const useEmployeeStore = defineStore('api-employee', () => { createEmployeeOtherInfo, editByIdEmployeeOtherInfo, - listAttachment, - getAttachment, uploadAttachment, deleteAttachment, attachment, listPassport, + + ...attachmentManager, ...fileManager, ...metaManager, };