refactor: add api Attachment

This commit is contained in:
Net 2024-09-16 10:26:16 +07:00
parent 487347d538
commit f6bcfb25cd

View file

@ -387,6 +387,41 @@ const useBranchStore = defineStore('api-branch', () => {
return false;
}
async function fetchListAttachment(branchId: string) {
const res = await api.get<string[]>(`branch/${branchId}/attachment`);
if (res.status === 200) {
return res.data;
}
}
async function fetchByIdAttachment(branchId: string, name: string) {
const res = await api.get<string>(`branch/${branchId}/attachment/${name}`);
if (res.status === 200) {
return res.data;
}
}
async function putAttachment(branchId: string, fileList: File[]) {
fileList.forEach(async (file) => {
await api
.put(`branch/${branchId}/attachment/${file.name}`, file, {
headers: { 'Content-Type': file.type },
onUploadProgress: (e) => console.log(e),
})
.catch((e) => console.error(e));
});
}
async function deleteByIdAttachment(branchId: string, name: string) {
const res = await api.delete(`branch/${branchId}/attachment/${name}`);
if (res.status === 204) {
return res.data;
}
}
return {
data,
map,
@ -410,6 +445,11 @@ const useBranchStore = defineStore('api-branch', () => {
stats,
userStats,
fetchListAttachment,
fetchByIdAttachment,
putAttachment,
deleteByIdAttachment,
};
});