refactor: customer

This commit is contained in:
puriphatt 2024-09-17 10:00:35 +07:00
parent 2ab96dc816
commit 234b03c7fa
12 changed files with 372 additions and 978 deletions

View file

@ -335,7 +335,6 @@ const useCustomerStore = defineStore('api-customer', () => {
) {
if (data.customerBranch) {
if (data.customerBranch[0].citizenId) {
console.log('1');
delete data.customerBranch[0]['authorizedNameEN'];
delete data.customerBranch[0]['authorizedName'];
delete data.customerBranch[0]['authorizedCapital'];
@ -368,7 +367,7 @@ const useCustomerStore = defineStore('api-customer', () => {
branchCode: undefined,
id: undefined,
customerId: undefined,
customerCode: undefined,
codeCustomer: undefined,
})),
selectedImage: imgList.selectedImage,
},
@ -404,18 +403,6 @@ const useCustomerStore = defineStore('api-customer', () => {
},
) {
const { customerBranch, image, ...payload } = data;
// const attachment = payload.customerBranch?.map((v) => v.file);
// payload.customerBranch = payload.customerBranch?.map((v) => {
// const { code: _code, ...rest } = v;
// return { ...rest };
// });
// if (payload.customerBranch?.length) {
// for (let i = 0; i < payload.customerBranch?.length; i++) {
// delete payload.customerBranch[i].file;
// }
// }
const res = await api.put<
Customer & {
@ -423,28 +410,32 @@ const useCustomerStore = defineStore('api-customer', () => {
imageUrl: string;
imageUploadUrl: string;
}
>(`/customer/${id}`, payload, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
>(
`/customer/${id}`,
{
...payload,
branch: data.customerBranch?.map((v) => ({
...v,
file: undefined,
branchCode: undefined,
id: undefined,
customerId: undefined,
codeCustomer: undefined,
createAt: undefined,
createdByUserId: undefined,
statusOrder: undefined,
updatedAt: undefined,
updatedByUserId: undefined,
})),
},
});
// await Promise.allSettled([
// ...res.data.branch.map(async (v, i) => {
// const fileList = attachment?.[i];
// if (fileList)
// return await addBranchAttachment(v.id, { file: fileList });
// }),
// image &&
// (await axios
// .put(res.data.imageUploadUrl, image, {
// headers: { 'Content-Type': image.type },
// onUploadProgress: (e) => console.log(e),
// })
// .catch((e) => console.error(e)));
// ]);
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
);
if (!res) return false;
@ -494,30 +485,35 @@ const useCustomerStore = defineStore('api-customer', () => {
}
async function createBranch(
data: CustomerBranchCreate & { id?: string; customerId: string },
data: CustomerBranchCreate & {
id?: string;
customerId: string;
codeCustomer: string;
},
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const {
customerCode,
registerCompanyName,
statusSave,
code,
file,
...payload
} = data;
const { codeCustomer, statusSave, code, file, birthDate, ...payload } =
data;
if (!!payload.citizenId) {
delete payload['registerDate'];
delete payload['registerName'];
delete payload['registerNameEN'];
delete payload['authorizedCapital'];
delete payload['legalPersonNo'];
if (data.citizenId) {
delete data['authorizedNameEN'];
delete data['authorizedName'];
delete data['registerDate'];
delete data['authorizedCapital'];
delete data['registerNameEN'];
delete data['registerName'];
delete data['legalPersonNo'];
} else {
delete payload['citizenId'];
delete data['citizenId'];
}
console.log(data.birthDate);
console.log(!data.birthDate);
if (!data.birthDate) {
delete data['birthDate'];
}
const res = await api.post<CustomerBranch>('/customer-branch', payload, {
@ -536,20 +532,44 @@ const useCustomerStore = defineStore('api-customer', () => {
async function editBranchById(
id: string,
data: Partial<CustomerBranchCreate & { id?: string; customerId: string }>,
data: Partial<
CustomerBranch & {
id?: string;
customerId: string;
codeCustomer: string;
}
>,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
if (data.citizenId) {
delete data['authorizedNameEN'];
delete data['authorizedName'];
delete data['registerDate'];
delete data['authorizedCapital'];
delete data['registerNameEN'];
delete data['registerName'];
delete data['legalPersonNo'];
} else {
delete data['citizenId'];
}
if (!data.birthDate) delete data['birthDate'];
const {
customerCode,
registerCompanyName,
statusSave,
code,
status,
codeCustomer,
createdAt,
createdByUserId,
statusOrder,
updatedAt,
updatedByUserId,
file,
registerCompanyName,
statusSave,
...payload
} = data;

View file

@ -30,33 +30,57 @@ export type Customer = {
};
export type CustomerBranch = {
customerId: string;
contactName: string;
wageRate: number;
payDate: string;
payDateEN: string;
jobDescription: string;
jobPosition: string;
businessType: string;
employmentOffice: string;
authorizedCapital: string;
registerDate: Date | null;
registerNameEN: string;
registerName: string;
legalPersonNo?: string;
citizenId: string;
updatedByUserId: string;
createdByUserId: string;
statusOrder: number;
telephoneNo: string;
email: string;
subDistrictId: string;
districtId: string;
provinceId: string;
addressEN: string;
address: string;
code: string;
id: string;
customerCode?: string;
wageRateText: 'string';
wageRate: 0;
payDateEN: 'string';
payDate: 'string';
jobDescription: 'string';
jobPosition: 'string';
businessType: 'string';
agent: 'string';
contactName: 'string';
officeTel: 'string';
contactTel: 'string';
email: 'string';
subDistrictId: 'string';
districtId: 'string';
provinceId: 'string';
streetEN: 'string';
street: 'string';
mooEN: 'string';
moo: 'string';
soiEN: 'string';
soi: 'string';
addressEN: 'string';
address: 'string';
employmentOfficeEN: 'string';
employmentOffice: 'string';
homeCode: 'string';
authorizedNameEN: 'string';
authorizedName: 'string';
authorizedCapital: 'string';
registerDate: '2024-09-16T07:52:42.627Z';
registerNameEN: 'string';
registerName: 'string';
legalPersonNo: 'string';
citizenId: 'string';
birthDate: '2024-09-16T07:52:42.627Z';
gender: 'string';
lastNameEN: 'string';
lastName: 'string';
firstNameEN: 'string';
firstName: 'string';
namePrefix: 'string';
telephoneNo: 'string';
codeCustomer: 'string';
customerName: 'string';
updatedByUserId: 'string';
createdByUserId: 'string';
code: 'string';
statusOrder: 0;
customerId: 'string';
id: 'string';
status: Status;
createdBy: string | null;
@ -72,6 +96,7 @@ export type CustomerBranch = {
};
export type CustomerBranchCreate = {
customerCode?: string;
customerId: string;
legalPersonNo?: string;
citizenId?: string;
@ -117,6 +142,7 @@ export type CustomerBranchCreate = {
authorizedCapital?: string;
authorizedName?: string;
authorizedNameEN?: string;
code?: 'string';
file?: {
name?: string;
group?: string;
@ -129,7 +155,7 @@ export type CustomerCreate = {
customerBranch?: (CustomerBranchCreate & {
id?: string;
branchCode?: string;
customerCode?: string;
codeCustomer?: string;
})[];
selectedImage?: string;
status?: Status;
@ -145,7 +171,7 @@ export type CustomerUpdate = {
customerBranch?: (CustomerBranchCreate & {
id?: string;
branchCode?: string;
customerCode?: string;
codeCustomer?: string;
})[];
image?: File;
registeredBranchId: string;