From f5626f9f2e76cfb350d6fd63c966c41202464e15 Mon Sep 17 00:00:00 2001 From: puriphatt Date: Tue, 22 Oct 2024 15:01:06 +0700 Subject: [PATCH] fix: quotation attachment --- src/stores/quotations/index.ts | 3 +-- src/stores/utils/index.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/stores/quotations/index.ts b/src/stores/quotations/index.ts index e4718017..4f99a99b 100644 --- a/src/stores/quotations/index.ts +++ b/src/stores/quotations/index.ts @@ -160,11 +160,10 @@ export const useQuotationPayment = defineStore('quotation-payment', () => { } function createPaymentFileManager( - api: AxiosInstance, quotationId: string, opts?: { onUploadProgress: (e: AxiosProgressEvent) => void }, ) { - return manageAttachment(api, `/quotation/${quotationId}/payment`, opts); + return manageAttachment(api, `quotation/${quotationId}/payment`, opts); } return { diff --git a/src/stores/utils/index.ts b/src/stores/utils/index.ts index da415c64..fd672e2d 100644 --- a/src/stores/utils/index.ts +++ b/src/stores/utils/index.ts @@ -288,15 +288,18 @@ export function manageAttachment( parentId: string; name: string; file: File; + onUploadProgress?: (e: AxiosProgressEvent) => void; }) => { const res = await api.put( `/${base}/${opts.parentId}/attachment/${opts.name}`, opts.file, { headers: { 'Content-Type': opts.file.type }, - onUploadProgress: option?.onUploadProgress - ? option.onUploadProgress - : (e) => console.log(e), + onUploadProgress: opts.onUploadProgress + ? opts.onUploadProgress + : option?.onUploadProgress + ? option.onUploadProgress + : (e) => console.log(e), }, ); if (res.status < 400) return true; @@ -470,4 +473,9 @@ export function convertFileSize(size: number): string { return sizeNumber.toFixed(2) + ' ' + units[i]; } +export async function getAttachmentHead(api: AxiosInstance, url: string) { + const res = await api.head(`${url}`); + if (res) return res.headers; +} + export default useUtilsStore;