feat: update emploee store for attachment function
This commit is contained in:
parent
69d1e1bc72
commit
1b040210b7
3 changed files with 94 additions and 18 deletions
|
|
@ -16,6 +16,7 @@ import {
|
|||
import { CustomerBranch } from '../customer/types';
|
||||
import axios from 'axios';
|
||||
import useFlowStore from '../flow';
|
||||
import { baseUrl } from '../utils';
|
||||
|
||||
const useEmployeeStore = defineStore('api-employee', () => {
|
||||
const flowStore = useFlowStore();
|
||||
|
|
@ -544,6 +545,57 @@ const useEmployeeStore = defineStore('api-employee', () => {
|
|||
}
|
||||
}
|
||||
|
||||
async function listAttachment(employeeId: string) {
|
||||
const res = await api.get<string[]>(`/employee/${employeeId}/attachment`);
|
||||
return !res || res.status >= 400 ? false : res.data;
|
||||
}
|
||||
async function getAttachment(
|
||||
employeeId: string,
|
||||
filename: string,
|
||||
download = false,
|
||||
) {
|
||||
const url = `${baseUrl}/employee/${employeeId}/attachment/${filename}`;
|
||||
const res = await api.get<string>(url);
|
||||
|
||||
if (download) {
|
||||
fetch(res.data)
|
||||
.then(async (res) => await res.blob())
|
||||
.then((blob) => {
|
||||
let a = document.createElement('a');
|
||||
a.download = filename;
|
||||
a.href = window.URL.createObjectURL(blob);
|
||||
a.click();
|
||||
a.remove();
|
||||
});
|
||||
}
|
||||
|
||||
return res.data;
|
||||
}
|
||||
async function uploadAttachment(
|
||||
employeeId: string,
|
||||
file: File,
|
||||
filename?: string,
|
||||
) {
|
||||
const res = await api.put(
|
||||
`/employee/${employeeId}/attachment/${filename || file.name}`,
|
||||
file,
|
||||
{
|
||||
headers: {
|
||||
'X-Rtid': flowStore.rtid,
|
||||
'Content-Type': file.type,
|
||||
},
|
||||
},
|
||||
);
|
||||
return !(!res || res.status >= 400);
|
||||
}
|
||||
async function deleteAttachment(employeeId: string, filename: string) {
|
||||
const res = await api.put(
|
||||
`/employee/${employeeId}/attachment/${filename}`,
|
||||
{ headers: { 'X-Rtid': flowStore.rtid } },
|
||||
);
|
||||
return !(!res || res.status >= 400);
|
||||
}
|
||||
|
||||
return {
|
||||
data,
|
||||
globalOption,
|
||||
|
|
@ -571,6 +623,11 @@ const useEmployeeStore = defineStore('api-employee', () => {
|
|||
|
||||
createEmployeeOtherInfo,
|
||||
editByIdEmployeeOtherInfo,
|
||||
|
||||
listAttachment,
|
||||
getAttachment,
|
||||
uploadAttachment,
|
||||
deleteAttachment,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -108,6 +108,12 @@ export type EmployeeCreate = {
|
|||
employeeCheckup?: EmployeeCheckupCreate[];
|
||||
|
||||
employeeOtherInfo?: EmployeeOtherCreate;
|
||||
|
||||
file?: {
|
||||
group?: string;
|
||||
url?: string;
|
||||
file?: File;
|
||||
}[];
|
||||
};
|
||||
|
||||
export type EmployeeUpdate = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue