refactor: add api Attachment
This commit is contained in:
parent
487347d538
commit
f6bcfb25cd
1 changed files with 40 additions and 0 deletions
|
|
@ -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,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue