feat: api customer citizen relation with upload
This commit is contained in:
parent
de105473a9
commit
e98540a4c9
2 changed files with 66 additions and 18 deletions
|
|
@ -254,24 +254,21 @@ const useCustomerStore = defineStore('api-customer', () => {
|
|||
|
||||
const { customerBranch, image, ...payload } = data;
|
||||
|
||||
const res = await api.post<
|
||||
Customer & {
|
||||
branch: CustomerBranch[];
|
||||
imageUrl: string;
|
||||
imageUploadUrl: string;
|
||||
}
|
||||
>('/customer', {
|
||||
...payload,
|
||||
branch: data.customerBranch?.map((v) => ({
|
||||
...v,
|
||||
file: undefined,
|
||||
branchCode: undefined,
|
||||
id: undefined,
|
||||
customerId: undefined,
|
||||
codeCustomer: undefined,
|
||||
})),
|
||||
selectedImage: imgList.selectedImage,
|
||||
});
|
||||
const res = await api.post<Customer & { branch: CustomerBranch[] }>(
|
||||
'/customer',
|
||||
{
|
||||
...payload,
|
||||
branch: data.customerBranch?.map((v) => ({
|
||||
...v,
|
||||
file: undefined,
|
||||
branchCode: undefined,
|
||||
id: undefined,
|
||||
customerId: undefined,
|
||||
codeCustomer: undefined,
|
||||
})),
|
||||
selectedImage: imgList.selectedImage,
|
||||
},
|
||||
);
|
||||
|
||||
if (imgList.list.length > 0 && res.data.id) {
|
||||
for (let index = 0; index < imgList.list.length; index++) {
|
||||
|
|
@ -283,6 +280,29 @@ const useCustomerStore = defineStore('api-customer', () => {
|
|||
|
||||
if (!res) return false;
|
||||
|
||||
await Promise.all(
|
||||
res.data.branch.map(async (v, i) => {
|
||||
const _citizen = customerBranch?.at(i)?.citizen;
|
||||
|
||||
if (_citizen) {
|
||||
for (let i = 0; i < _citizen.length; i++) {
|
||||
const _res = await api.post<{ id: string }>(
|
||||
`/customer-branch/${v.id}/citizen`,
|
||||
_citizen[i],
|
||||
);
|
||||
if (_res.data.id) {
|
||||
await fileManager.putFile({
|
||||
group: 'citizen',
|
||||
parentId: v.id,
|
||||
file: _citizen[i].file,
|
||||
fileId: _res.data.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
return res.data;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -143,6 +143,7 @@ export type CustomerBranchCreate = {
|
|||
authorizedName?: string;
|
||||
authorizedNameEN?: string;
|
||||
code?: 'string';
|
||||
citizen?: CitizenPayload[];
|
||||
file?: {
|
||||
name?: string;
|
||||
group?: string;
|
||||
|
|
@ -199,3 +200,30 @@ export type CustomerStats = {
|
|||
CORP: number;
|
||||
PERS: number;
|
||||
};
|
||||
|
||||
export type CitizenPayload = {
|
||||
namePrefix?: string;
|
||||
firstName: string;
|
||||
firstNameEN?: string;
|
||||
middleName?: string;
|
||||
middleNameEN?: string;
|
||||
lastName: string;
|
||||
lastNameEN?: string;
|
||||
issueDate: Date;
|
||||
expireDate: Date;
|
||||
nationality: string;
|
||||
religion: string;
|
||||
gender: string;
|
||||
address?: string;
|
||||
addressEN?: string;
|
||||
soi?: string;
|
||||
soiEN?: string;
|
||||
moo?: string;
|
||||
mooEN?: string;
|
||||
street?: string;
|
||||
streetEN?: string;
|
||||
provinceId?: string;
|
||||
districtId?: string;
|
||||
subDistrictId?: string;
|
||||
file: File;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue