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 { customerBranch, image, ...payload } = data;
|
||||||
|
|
||||||
const res = await api.post<
|
const res = await api.post<Customer & { branch: CustomerBranch[] }>(
|
||||||
Customer & {
|
'/customer',
|
||||||
branch: CustomerBranch[];
|
{
|
||||||
imageUrl: string;
|
...payload,
|
||||||
imageUploadUrl: string;
|
branch: data.customerBranch?.map((v) => ({
|
||||||
}
|
...v,
|
||||||
>('/customer', {
|
file: undefined,
|
||||||
...payload,
|
branchCode: undefined,
|
||||||
branch: data.customerBranch?.map((v) => ({
|
id: undefined,
|
||||||
...v,
|
customerId: undefined,
|
||||||
file: undefined,
|
codeCustomer: undefined,
|
||||||
branchCode: undefined,
|
})),
|
||||||
id: undefined,
|
selectedImage: imgList.selectedImage,
|
||||||
customerId: undefined,
|
},
|
||||||
codeCustomer: undefined,
|
);
|
||||||
})),
|
|
||||||
selectedImage: imgList.selectedImage,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (imgList.list.length > 0 && res.data.id) {
|
if (imgList.list.length > 0 && res.data.id) {
|
||||||
for (let index = 0; index < imgList.list.length; index++) {
|
for (let index = 0; index < imgList.list.length; index++) {
|
||||||
|
|
@ -283,6 +280,29 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
|
|
||||||
if (!res) return false;
|
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;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,7 @@ export type CustomerBranchCreate = {
|
||||||
authorizedName?: string;
|
authorizedName?: string;
|
||||||
authorizedNameEN?: string;
|
authorizedNameEN?: string;
|
||||||
code?: 'string';
|
code?: 'string';
|
||||||
|
citizen?: CitizenPayload[];
|
||||||
file?: {
|
file?: {
|
||||||
name?: string;
|
name?: string;
|
||||||
group?: string;
|
group?: string;
|
||||||
|
|
@ -199,3 +200,30 @@ export type CustomerStats = {
|
||||||
CORP: number;
|
CORP: number;
|
||||||
PERS: 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