diff --git a/src/stores/utils/index.ts b/src/stores/utils/index.ts index 786b3b7e..3dafe67c 100644 --- a/src/stores/utils/index.ts +++ b/src/stores/utils/index.ts @@ -237,8 +237,10 @@ export function resetScrollBar(elementId: string) { export function manageAttachment(api: AxiosInstance, base: string) { return { - listAttachment: async () => { - const res = await api.get(`${base}/attachment`); + listAttachment: async (opts: { parentId: string }) => { + const res = await api.get( + `${base}/${opts.parentId}/attachment`, + ); if (res.status >= 400) return false; return res.data; }, @@ -247,7 +249,7 @@ export function manageAttachment(api: AxiosInstance, base: string) { name: string; download?: boolean; }) => { - const url = `/${opts.parentId}/attachment/${opts.name}`; + const url = `${base}/${opts.parentId}/attachment/${opts.name}`; const res = await api.get(url); if (opts.download) { fetch(res.data) @@ -268,7 +270,7 @@ export function manageAttachment(api: AxiosInstance, base: string) { file: File; }) => { const res = await api.put( - `/${opts.parentId}/attachment/${opts.name}`, + `${base}/${opts.parentId}/attachment/${opts.name}`, opts.file, { headers: { 'Content-Type': opts.file.type }, @@ -279,7 +281,9 @@ export function manageAttachment(api: AxiosInstance, base: string) { return false; }, delAttachment: async (opts: { parentId: string; name: string }) => { - const res = await api.delete(`/${opts.parentId}/attachment/${opts.name}`); + const res = await api.delete( + `${base}/${opts.parentId}/attachment/${opts.name}`, + ); if (res.status < 400) return true; return false; }, @@ -288,8 +292,10 @@ export function manageAttachment(api: AxiosInstance, base: string) { export function manageFile(api: AxiosInstance, base: string) { return { - listFile: async (opts: { group: T }) => { - const res = await api.get(`${base}/file-${opts.group}`); + listFile: async (opts: { group: T; parentId: string }) => { + const res = await api.get( + `${base}/${opts.parentId}/file-${opts.group}`, + ); if (res.status >= 400) return false; return res.data; }, @@ -299,7 +305,7 @@ export function manageFile(api: AxiosInstance, base: string) { fileId: string; download?: boolean; }) => { - const url = `/${opts.parentId}/file-${opts.group}/${opts.fileId}`; + const url = `${base}/${opts.parentId}/file-${opts.group}/${opts.fileId}`; const res = await api.get(url); if (opts.download) { fetch(res.data) @@ -321,7 +327,7 @@ export function manageFile(api: AxiosInstance, base: string) { file: File; }) => { const res = await api.put( - `/${opts.parentId}/file-${opts.group}/${opts.fileId}`, + `${base}/${opts.parentId}/file-${opts.group}/${opts.fileId}`, opts.file, { headers: { 'Content-Type': opts.file.type }, @@ -333,7 +339,7 @@ export function manageFile(api: AxiosInstance, base: string) { }, delFile: async (opts: { group: T; parentId: string; fileId: string }) => { const res = await api.delete( - `/${opts.parentId}/file-${opts.group}/${opts.fileId}`, + `${base}/${opts.parentId}/file-${opts.group}/${opts.fileId}`, ); if (res.status < 400) return true; return false;