From 633fc381600981cf660ffb48be828e9522781204 Mon Sep 17 00:00:00 2001 From: Net Date: Mon, 23 Sep 2024 17:46:09 +0700 Subject: [PATCH] refactor: edit type file on create --- src/stores/branch/index.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/stores/branch/index.ts b/src/stores/branch/index.ts index e63f6a29..20dcfc8a 100644 --- a/src/stores/branch/index.ts +++ b/src/stores/branch/index.ts @@ -148,6 +148,7 @@ const useBranchStore = defineStore('api-branch', () => { selectedImage: string; list: { url: string; imgFile: File | null; name: string }[]; }, + fileItem?: { name?: string; group?: string; url?: string; file?: File }[], ) { const { qrCodeImage, zipCode, ...payload } = branch; const bankPayload = bank?.map(({ bankUrl, bankQr, ...rest }) => ({ @@ -164,6 +165,14 @@ const useBranchStore = defineStore('api-branch', () => { { headers: { 'X-Rtid': flowStore.rtid } }, ); + if (fileItem !== undefined) { + fileItem.forEach(async (v) => { + if (v.file === undefined) return; + + await putAttachment(res.data.id, v.file); + }); + } + if (qrCodeImage) { await api .put(`/branch/${res.data.id}/line-image`, qrCodeImage, { @@ -403,15 +412,13 @@ const useBranchStore = defineStore('api-branch', () => { } } - 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 putAttachment(branchId: string, file: 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) {