feat: create citizenId relation
This commit is contained in:
parent
d66c3d7856
commit
fe3532eabd
1 changed files with 27 additions and 4 deletions
|
|
@ -10,6 +10,7 @@ import {
|
||||||
CustomerBranch,
|
CustomerBranch,
|
||||||
CustomerBranchCreate,
|
CustomerBranchCreate,
|
||||||
CustomerType,
|
CustomerType,
|
||||||
|
CitizenPayload,
|
||||||
} from './types';
|
} from './types';
|
||||||
import { Employee } from '../employee/types';
|
import { Employee } from '../employee/types';
|
||||||
import { baseUrl, manageFile } from '../utils';
|
import { baseUrl, manageFile } from '../utils';
|
||||||
|
|
@ -312,8 +313,6 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
const res = await api.put<
|
const res = await api.put<
|
||||||
Customer & {
|
Customer & {
|
||||||
branch: CustomerBranch[];
|
branch: CustomerBranch[];
|
||||||
imageUrl: string;
|
|
||||||
imageUploadUrl: string;
|
|
||||||
}
|
}
|
||||||
>(`/customer/${id}`, {
|
>(`/customer/${id}`, {
|
||||||
...payload,
|
...payload,
|
||||||
|
|
@ -360,8 +359,15 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
codeCustomer: string;
|
codeCustomer: string;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
const { codeCustomer, statusSave, code, file, birthDate, ...payload } =
|
const {
|
||||||
data;
|
codeCustomer,
|
||||||
|
statusSave,
|
||||||
|
code,
|
||||||
|
file,
|
||||||
|
birthDate,
|
||||||
|
citizen,
|
||||||
|
...payload
|
||||||
|
} = data;
|
||||||
|
|
||||||
if (data.citizenId) {
|
if (data.citizenId) {
|
||||||
delete data['authorizedNameEN'];
|
delete data['authorizedNameEN'];
|
||||||
|
|
@ -383,6 +389,23 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
const res = await api.post<CustomerBranch>('/customer-branch', payload);
|
const res = await api.post<CustomerBranch>('/customer-branch', payload);
|
||||||
if (!res) return false;
|
if (!res) return false;
|
||||||
|
|
||||||
|
if (citizen) {
|
||||||
|
for (let i = 0; i < citizen.length; i++) {
|
||||||
|
const _res = await api.post<{ id: string }>(
|
||||||
|
`/customer-branch/${res.data.id}/citizen`,
|
||||||
|
citizen[i],
|
||||||
|
);
|
||||||
|
if (_res.data.id) {
|
||||||
|
await fileManager.putFile({
|
||||||
|
group: 'citizen',
|
||||||
|
parentId: res.data.id,
|
||||||
|
file: citizen[i].file,
|
||||||
|
fileId: _res.data.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue