From f6bcfb25cd09cc4cb666365a40a43a3bdbe82c03 Mon Sep 17 00:00:00 2001 From: Net Date: Mon, 16 Sep 2024 10:26:16 +0700 Subject: [PATCH] refactor: add api Attachment --- src/stores/branch/index.ts | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/stores/branch/index.ts b/src/stores/branch/index.ts index 8d96f4ac..8afef92f 100644 --- a/src/stores/branch/index.ts +++ b/src/stores/branch/index.ts @@ -387,6 +387,41 @@ const useBranchStore = defineStore('api-branch', () => { return false; } + async function fetchListAttachment(branchId: string) { + const res = await api.get(`branch/${branchId}/attachment`); + + if (res.status === 200) { + return res.data; + } + } + + async function fetchByIdAttachment(branchId: string, name: string) { + const res = await api.get(`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, }; });