refactor: edit function get attachment
This commit is contained in:
parent
c7bfa4bb5f
commit
5040b64682
1 changed files with 46 additions and 46 deletions
|
|
@ -216,15 +216,15 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
transactionId?: string;
|
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) {
|
// if (payload.customerBranch?.length) {
|
||||||
for (let i = 0; i < payload.customerBranch?.length; i++) {
|
// for (let i = 0; i < payload.customerBranch?.length; i++) {
|
||||||
delete payload.customerBranch[i].file;
|
// delete payload.customerBranch[i].file;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
const res = await api.post<
|
const res = await api.post<
|
||||||
Customer & {
|
Customer & {
|
||||||
|
|
@ -240,20 +240,20 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.allSettled([
|
// await Promise.allSettled([
|
||||||
...res.data.branch.map(async (v, i) => {
|
// ...res.data.branch.map(async (v, i) => {
|
||||||
const fileList = attachment?.[i];
|
// const fileList = attachment?.[i];
|
||||||
if (fileList)
|
// if (fileList)
|
||||||
return await addBranchAttachment(v.id, { file: fileList });
|
// return await addBranchAttachment(v.id, { file: fileList });
|
||||||
}),
|
// }),
|
||||||
image &&
|
image &&
|
||||||
(await api
|
(await api
|
||||||
.put(`/customer/${res.data.id}/image`, image, {
|
.put(`/customer/${res.data.id}/image`, image, {
|
||||||
headers: { 'Content-Type': image?.type },
|
headers: { 'Content-Type': image?.type },
|
||||||
onUploadProgress: (e) => console.log(e),
|
onUploadProgress: (e) => console.log(e),
|
||||||
})
|
})
|
||||||
.catch((e) => console.error(e))),
|
.catch((e) => console.error(e)));
|
||||||
]);
|
// ]);
|
||||||
|
|
||||||
if (!res) return false;
|
if (!res) return false;
|
||||||
|
|
||||||
|
|
@ -269,19 +269,19 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
transactionId?: string;
|
transactionId?: string;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const { image, ...payload } = data;
|
const { customerBranch, image, ...payload } = data;
|
||||||
const attachment = payload.customerBranch?.map((v) => v.file);
|
// const attachment = payload.customerBranch?.map((v) => v.file);
|
||||||
|
|
||||||
payload.customerBranch = payload.customerBranch?.map((v) => {
|
// payload.customerBranch = payload.customerBranch?.map((v) => {
|
||||||
const { code: _code, ...rest } = v;
|
// const { code: _code, ...rest } = v;
|
||||||
return { ...rest };
|
// return { ...rest };
|
||||||
});
|
// });
|
||||||
|
|
||||||
if (payload.customerBranch?.length) {
|
// if (payload.customerBranch?.length) {
|
||||||
for (let i = 0; i < payload.customerBranch?.length; i++) {
|
// for (let i = 0; i < payload.customerBranch?.length; i++) {
|
||||||
delete payload.customerBranch[i].file;
|
// delete payload.customerBranch[i].file;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
const res = await api.put<
|
const res = await api.put<
|
||||||
Customer & {
|
Customer & {
|
||||||
|
|
@ -297,20 +297,20 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.allSettled([
|
// await Promise.allSettled([
|
||||||
...res.data.branch.map(async (v, i) => {
|
// ...res.data.branch.map(async (v, i) => {
|
||||||
const fileList = attachment?.[i];
|
// const fileList = attachment?.[i];
|
||||||
if (fileList)
|
// if (fileList)
|
||||||
return await addBranchAttachment(v.id, { file: fileList });
|
// return await addBranchAttachment(v.id, { file: fileList });
|
||||||
}),
|
// }),
|
||||||
image &&
|
image &&
|
||||||
(await axios
|
(await axios
|
||||||
.put(res.data.imageUploadUrl, image, {
|
.put(res.data.imageUploadUrl, image, {
|
||||||
headers: { 'Content-Type': image.type },
|
headers: { 'Content-Type': image.type },
|
||||||
onUploadProgress: (e) => console.log(e),
|
onUploadProgress: (e) => console.log(e),
|
||||||
})
|
})
|
||||||
.catch((e) => console.error(e))),
|
.catch((e) => console.error(e)));
|
||||||
]);
|
// ]);
|
||||||
|
|
||||||
if (!res) return false;
|
if (!res) return false;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue