diff --git a/src/stores/branch/index.ts b/src/stores/branch/index.ts index da27c519..5365f757 100644 --- a/src/stores/branch/index.ts +++ b/src/stores/branch/index.ts @@ -124,10 +124,14 @@ const useBranchStore = defineStore('api-branch', () => { transactionId: string; }, ) { - const { qrCodeImage, ...payload } = branch; + const { qrCodeImage, imageUrl, ...payload } = branch; const res = await api.post< - Branch & { qrCodeImageUrl: string; qrCodeImageUploadUrl: string } + Branch & { + qrCodeImageUrl: string; + qrCodeImageUploadUrl: string; + imageUploadUrl: string; + } >('/branch', payload, { headers: { 'X-Session-Id': flow?.sessionId, @@ -143,6 +147,16 @@ const useBranchStore = defineStore('api-branch', () => { onUploadProgress: (e) => console.log(e), }) .catch((e) => console.error(e))); + + if (imageUrl) { + await axios + .put(res.data.imageUploadUrl, imageUrl, { + headers: { 'Content-Type': imageUrl.type }, + onUploadProgress: (e) => console.log(e), + }) + .catch((e) => console.error(e)); + } + if (!res) return false; return res.data; @@ -151,7 +165,8 @@ const useBranchStore = defineStore('api-branch', () => { async function editById( id: string, data: Partial, - qrCodeImage?: File, + qrCodeImage?: File | undefined, + imageHq?: File | undefined, flow?: { sessionId: string; refTransactionId: string; @@ -159,17 +174,15 @@ const useBranchStore = defineStore('api-branch', () => { }, ) { const { ...payload } = data; - const res = await api.put( - `/branch/${id}`, - payload, - { - headers: { - 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, - 'X-Tid': flow?.transactionId, - }, + const res = await api.put< + Branch & { qrCodeImageUploadUrl: string; imageUploadUrl: string } + >(`/branch/${id}`, payload, { + headers: { + 'X-Session-Id': flow?.sessionId, + 'X-Rtid': flow?.refTransactionId, + 'X-Tid': flow?.transactionId, }, - ); + }); if (qrCodeImage) { await axios @@ -180,6 +193,15 @@ const useBranchStore = defineStore('api-branch', () => { .catch((e) => console.error(e)); } + if (imageHq) { + await axios + .put(res.data.imageUploadUrl, imageHq, { + headers: { 'Content-Type': imageHq.type }, + onUploadProgress: (e) => console.log(e), + }) + .catch((e) => console.error(e)); + } + if (!res) return false; return res.data;