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; selectedImage: string;
list: { url: string; imgFile: File | null; name: string }[]; list: { url: string; imgFile: File | null; name: string }[];
}, },
fileItem?: { name?: string; group?: string; url?: string; file?: File }[],
) { ) {
const { qrCodeImage, zipCode, ...payload } = branch; const { qrCodeImage, zipCode, ...payload } = branch;
const bankPayload = bank?.map(({ bankUrl, bankQr, ...rest }) => ({ const bankPayload = bank?.map(({ bankUrl, bankQr, ...rest }) => ({
@ -164,6 +165,14 @@ const useBranchStore = defineStore('api-branch', () => {
{ headers: { 'X-Rtid': flowStore.rtid } }, { 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) { if (qrCodeImage) {
await api await api
.put(`/branch/${res.data.id}/line-image`, qrCodeImage, { .put(`/branch/${res.data.id}/line-image`, qrCodeImage, {
@ -403,15 +412,13 @@ const useBranchStore = defineStore('api-branch', () => {
} }
} }
async function putAttachment(branchId: string, fileList: File[]) { async function putAttachment(branchId: string, file: File) {
fileList.forEach(async (file) => { await api
await api .put(`branch/${branchId}/attachment/${file.name}`, file, {
.put(`branch/${branchId}/attachment/${file.name}`, file, { headers: { 'Content-Type': file.type },
headers: { 'Content-Type': file.type }, onUploadProgress: (e) => console.log(e),
onUploadProgress: (e) => console.log(e), })
}) .catch((e) => console.error(e));
.catch((e) => console.error(e));
});
} }
async function deleteByIdAttachment(branchId: string, name: string) { async function deleteByIdAttachment(branchId: string, name: string) {