feat: add attachment to customer branch
This commit is contained in:
parent
3a0e35072b
commit
f3a146e345
2 changed files with 95 additions and 45 deletions
|
|
@ -8,6 +8,7 @@ import {
|
||||||
CustomerUpdate,
|
CustomerUpdate,
|
||||||
BranchAttachmentCreate,
|
BranchAttachmentCreate,
|
||||||
BranchAttachment,
|
BranchAttachment,
|
||||||
|
CustomerBranch,
|
||||||
} from './types';
|
} from './types';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
|
|
@ -61,12 +62,21 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
transactionId: string;
|
transactionId: string;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
const { image, ...payload } = data;
|
const { image, ...payload } = data;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const res = await api.post<
|
const res = await api.post<
|
||||||
Customer & { imageUrl: string; imageUploadUrl: string }
|
Customer & {
|
||||||
|
branch: CustomerBranch[];
|
||||||
|
imageUrl: string;
|
||||||
|
imageUploadUrl: string;
|
||||||
|
}
|
||||||
>('/customer', payload, {
|
>('/customer', payload, {
|
||||||
headers: {
|
headers: {
|
||||||
'X-Session-Id': flow?.sessionId,
|
'X-Session-Id': flow?.sessionId,
|
||||||
|
|
@ -75,12 +85,19 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await axios
|
await Promise.allSettled([
|
||||||
.put(res.data.imageUploadUrl, image, {
|
...res.data.branch.map(async (v, i) => {
|
||||||
headers: { 'Content-Type': image.type },
|
const fileList = attachment?.[i];
|
||||||
onUploadProgress: (e) => console.log(e),
|
if (fileList)
|
||||||
})
|
return await addBranchAttachment(v.id, { file: fileList });
|
||||||
.catch((e) => console.error(e));
|
}),
|
||||||
|
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;
|
if (!res) return false;
|
||||||
|
|
||||||
|
|
@ -97,8 +114,20 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const { image, ...payload } = data;
|
const { image, ...payload } = data;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const res = await api.put<
|
const res = await api.put<
|
||||||
Customer & { imageUrl: string; imageUploadUrl: string }
|
Customer & {
|
||||||
|
branch: CustomerBranch[];
|
||||||
|
imageUrl: string;
|
||||||
|
imageUploadUrl: string;
|
||||||
|
}
|
||||||
>(`/customer/${id}`, payload, {
|
>(`/customer/${id}`, payload, {
|
||||||
headers: {
|
headers: {
|
||||||
'X-Session-Id': flow?.sessionId,
|
'X-Session-Id': flow?.sessionId,
|
||||||
|
|
@ -107,13 +136,20 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (image)
|
await Promise.allSettled([
|
||||||
await axios
|
...res.data.branch.map(async (v, i) => {
|
||||||
.put(res.data.imageUploadUrl, image, {
|
const fileList = attachment?.[i];
|
||||||
headers: { 'Content-Type': image.type },
|
if (fileList)
|
||||||
onUploadProgress: (e) => console.log(e),
|
return await addBranchAttachment(v.id, { file: fileList });
|
||||||
})
|
}),
|
||||||
.catch((e) => console.error(e));
|
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;
|
if (!res) return false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { District, Province, SubDistrict } from '../address';
|
||||||
import { Status } from '../types';
|
import { Status } from '../types';
|
||||||
|
|
||||||
export type CustomerType = 'CORP' | 'PERS';
|
export type CustomerType = 'CORP' | 'PERS';
|
||||||
|
|
@ -11,9 +12,47 @@ export type Customer = {
|
||||||
customerNameEN: string;
|
customerNameEN: string;
|
||||||
status: Status;
|
status: Status;
|
||||||
createdBy: string | null;
|
createdBy: string | null;
|
||||||
createdAt: Date;
|
createdAt: string;
|
||||||
updateBy: string | null;
|
updateBy: string | null;
|
||||||
updatedAt: Date;
|
updatedAt: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CustomerBranch = {
|
||||||
|
id: string;
|
||||||
|
branchNo: string;
|
||||||
|
legalPersonNo: string;
|
||||||
|
name: string;
|
||||||
|
nameEN: string;
|
||||||
|
customerId: string;
|
||||||
|
taxNo: string;
|
||||||
|
registerName: string;
|
||||||
|
registerDate: string;
|
||||||
|
authorizedCapital: string;
|
||||||
|
address: string;
|
||||||
|
addressEN: string;
|
||||||
|
provinceId: string | null;
|
||||||
|
districtId: string | null;
|
||||||
|
subDistrictId: string | null;
|
||||||
|
zipCode: string;
|
||||||
|
email: string;
|
||||||
|
telephoneNo: string;
|
||||||
|
employmentOffice: string;
|
||||||
|
bussinessType: string;
|
||||||
|
bussinessTypeEN: string;
|
||||||
|
jobPosition: string;
|
||||||
|
jobPositionEN: string;
|
||||||
|
jobDescription: string;
|
||||||
|
saleEmployee: string;
|
||||||
|
payDate: string;
|
||||||
|
wageDate: string;
|
||||||
|
status: Status;
|
||||||
|
createdBy: string | null;
|
||||||
|
createdAt: string;
|
||||||
|
updateBy: string | null;
|
||||||
|
updatedAt: string;
|
||||||
|
province: Province;
|
||||||
|
district: District;
|
||||||
|
subDistrict: SubDistrict;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CustomerBranchCreate = {
|
export type CustomerBranchCreate = {
|
||||||
|
|
@ -42,6 +81,7 @@ export type CustomerBranchCreate = {
|
||||||
saleEmployee: string;
|
saleEmployee: string;
|
||||||
payDate: string;
|
payDate: string;
|
||||||
wageDate: string;
|
wageDate: string;
|
||||||
|
file?: File[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CustomerCreate = {
|
export type CustomerCreate = {
|
||||||
|
|
@ -54,32 +94,6 @@ export type CustomerCreate = {
|
||||||
image: File;
|
image: File;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CustomerBranchUpdate = {
|
|
||||||
id: string;
|
|
||||||
status?: 'ACTIVE' | 'INACTIVE';
|
|
||||||
|
|
||||||
legalPersonNo?: string;
|
|
||||||
|
|
||||||
taxNo?: string;
|
|
||||||
name?: string;
|
|
||||||
nameEN?: string;
|
|
||||||
addressEN?: string;
|
|
||||||
address?: string;
|
|
||||||
zipCode?: string;
|
|
||||||
email?: string;
|
|
||||||
telephoneNo?: string;
|
|
||||||
longitude?: string;
|
|
||||||
latitude?: string;
|
|
||||||
|
|
||||||
registerName?: string;
|
|
||||||
registerDate?: Date;
|
|
||||||
authorizedCapital?: string;
|
|
||||||
|
|
||||||
subDistrictId?: string | null;
|
|
||||||
districtId?: string | null;
|
|
||||||
provinceId?: string | null;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type CustomerUpdate = {
|
export type CustomerUpdate = {
|
||||||
status?: 'ACTIVE' | 'INACTIVE';
|
status?: 'ACTIVE' | 'INACTIVE';
|
||||||
customerType?: CustomerType;
|
customerType?: CustomerType;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue