refactor: edit type file on create

This commit is contained in:
Net 2024-09-23 17:46:09 +07:00
parent f3fd874b8f
commit 633fc38160

View file

@ -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) {