refactor: edit function get attachment

This commit is contained in:
Net 2024-08-20 18:05:21 +07:00
parent c7bfa4bb5f
commit 5040b64682

View file

@ -216,15 +216,15 @@ const useCustomerStore = defineStore('api-customer', () => {
transactionId?: string;
},
) {
const { image, ...payload } = data;
const { code, customerBranch, image, ...payload } = data;
const attachment = payload.customerBranch?.map((v) => v.file);
// const attachment = payload.customerBranch?.map((v) => v.file);
if (payload.customerBranch?.length) {
for (let i = 0; i < payload.customerBranch?.length; i++) {
delete payload.customerBranch[i].file;
}
}
// if (payload.customerBranch?.length) {
// for (let i = 0; i < payload.customerBranch?.length; i++) {
// delete payload.customerBranch[i].file;
// }
// }
const res = await api.post<
Customer & {
@ -240,20 +240,20 @@ const useCustomerStore = defineStore('api-customer', () => {
},
});
await Promise.allSettled([
...res.data.branch.map(async (v, i) => {
const fileList = attachment?.[i];
if (fileList)
return await addBranchAttachment(v.id, { file: fileList });
}),
image &&
(await api
.put(`/customer/${res.data.id}/image`, image, {
headers: { 'Content-Type': image?.type },
onUploadProgress: (e) => console.log(e),
})
.catch((e) => console.error(e))),
]);
// await Promise.allSettled([
// ...res.data.branch.map(async (v, i) => {
// const fileList = attachment?.[i];
// if (fileList)
// return await addBranchAttachment(v.id, { file: fileList });
// }),
image &&
(await api
.put(`/customer/${res.data.id}/image`, image, {
headers: { 'Content-Type': image?.type },
onUploadProgress: (e) => console.log(e),
})
.catch((e) => console.error(e)));
// ]);
if (!res) return false;
@ -269,19 +269,19 @@ const useCustomerStore = defineStore('api-customer', () => {
transactionId?: string;
},
) {
const { image, ...payload } = data;
const attachment = payload.customerBranch?.map((v) => v.file);
const { customerBranch, image, ...payload } = data;
// const attachment = payload.customerBranch?.map((v) => v.file);
payload.customerBranch = payload.customerBranch?.map((v) => {
const { code: _code, ...rest } = v;
return { ...rest };
});
// payload.customerBranch = payload.customerBranch?.map((v) => {
// const { code: _code, ...rest } = v;
// return { ...rest };
// });
if (payload.customerBranch?.length) {
for (let i = 0; i < payload.customerBranch?.length; i++) {
delete payload.customerBranch[i].file;
}
}
// if (payload.customerBranch?.length) {
// for (let i = 0; i < payload.customerBranch?.length; i++) {
// delete payload.customerBranch[i].file;
// }
// }
const res = await api.put<
Customer & {
@ -297,20 +297,20 @@ const useCustomerStore = defineStore('api-customer', () => {
},
});
await Promise.allSettled([
...res.data.branch.map(async (v, i) => {
const fileList = attachment?.[i];
if (fileList)
return await addBranchAttachment(v.id, { file: fileList });
}),
image &&
(await axios
.put(res.data.imageUploadUrl, image, {
headers: { 'Content-Type': image.type },
onUploadProgress: (e) => console.log(e),
})
.catch((e) => console.error(e))),
]);
// await Promise.allSettled([
// ...res.data.branch.map(async (v, i) => {
// const fileList = attachment?.[i];
// if (fileList)
// return await addBranchAttachment(v.id, { file: fileList });
// }),
image &&
(await axios
.put(res.data.imageUploadUrl, image, {
headers: { 'Content-Type': image.type },
onUploadProgress: (e) => console.log(e),
})
.catch((e) => console.error(e)));
// ]);
if (!res) return false;