fix: quotation attachment

This commit is contained in:
puriphatt 2024-10-22 15:01:06 +07:00
parent 7ae74cdd5d
commit f5626f9f2e
2 changed files with 12 additions and 5 deletions

View file

@ -160,11 +160,10 @@ export const useQuotationPayment = defineStore('quotation-payment', () => {
} }
function createPaymentFileManager( function createPaymentFileManager(
api: AxiosInstance,
quotationId: string, quotationId: string,
opts?: { onUploadProgress: (e: AxiosProgressEvent) => void }, opts?: { onUploadProgress: (e: AxiosProgressEvent) => void },
) { ) {
return manageAttachment(api, `/quotation/${quotationId}/payment`, opts); return manageAttachment(api, `quotation/${quotationId}/payment`, opts);
} }
return { return {

View file

@ -288,15 +288,18 @@ export function manageAttachment(
parentId: string; parentId: string;
name: string; name: string;
file: File; file: File;
onUploadProgress?: (e: AxiosProgressEvent) => void;
}) => { }) => {
const res = await api.put( const res = await api.put(
`/${base}/${opts.parentId}/attachment/${opts.name}`, `/${base}/${opts.parentId}/attachment/${opts.name}`,
opts.file, opts.file,
{ {
headers: { 'Content-Type': opts.file.type }, headers: { 'Content-Type': opts.file.type },
onUploadProgress: option?.onUploadProgress onUploadProgress: opts.onUploadProgress
? option.onUploadProgress ? opts.onUploadProgress
: (e) => console.log(e), : option?.onUploadProgress
? option.onUploadProgress
: (e) => console.log(e),
}, },
); );
if (res.status < 400) return true; if (res.status < 400) return true;
@ -470,4 +473,9 @@ export function convertFileSize(size: number): string {
return sizeNumber.toFixed(2) + ' ' + units[i]; return sizeNumber.toFixed(2) + ' ' + units[i];
} }
export async function getAttachmentHead(api: AxiosInstance, url: string) {
const res = await api.head<string>(`${url}`);
if (res) return res.headers;
}
export default useUtilsStore; export default useUtilsStore;