refactor: ลบ code ออก ตอนส่ง

This commit is contained in:
Net 2024-07-03 17:56:07 +07:00
parent 2d4ecfebba
commit 472d477d7e

View file

@ -28,16 +28,15 @@ const useCustomerStore = defineStore('api-customer', () => {
transactionId?: string; transactionId?: string;
}, },
) { ) {
const res = await api.get<Customer & { branch: CustomerBranch[] }>( const res = await api.get<
`/customer/${customerId}`, Customer & { branch: CustomerBranch[]; registeredBranchId: string }
{ >(`/customer/${customerId}`, {
headers: { headers: {
'X-Session-Id': flow?.sessionId, 'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId, 'X-Tid': flow?.transactionId,
},
}, },
); });
if (res && res.status === 200) { if (res && res.status === 200) {
return res.data; return res.data;
@ -46,7 +45,7 @@ const useCustomerStore = defineStore('api-customer', () => {
return false; return false;
} }
async function fetchListBranch< async function fetchListCustomeBranch<
Options extends { Options extends {
zipCode?: string; zipCode?: string;
customerId?: string; customerId?: string;
@ -173,8 +172,14 @@ const useCustomerStore = defineStore('api-customer', () => {
}, },
) { ) {
const { image, ...payload } = data; const { image, ...payload } = data;
const attachment = payload.customerBranch?.map((v) => v.file); const attachment = payload.customerBranch?.map((v) => v.file);
payload.customerBranch = payload.customerBranch?.map((v) => {
delete v['code'];
return { ...v };
});
if (payload.customerBranch?.length) { if (payload.customerBranch?.length) {
for (let i = 0; i < payload.customerBranch?.length; i++) { for (let i = 0; i < payload.customerBranch?.length; i++) {
delete payload.customerBranch[i].file; delete payload.customerBranch[i].file;
@ -227,6 +232,11 @@ const useCustomerStore = defineStore('api-customer', () => {
const { image, ...payload } = data; const { image, ...payload } = data;
const attachment = payload.customerBranch?.map((v) => v.file); const attachment = payload.customerBranch?.map((v) => v.file);
payload.customerBranch = payload.customerBranch?.map((v) => {
const { code, ...rest } = v;
return { ...rest };
});
if (payload.customerBranch?.length) { if (payload.customerBranch?.length) {
for (let i = 0; i < payload.customerBranch?.length; i++) { for (let i = 0; i < payload.customerBranch?.length; i++) {
delete payload.customerBranch[i].file; delete payload.customerBranch[i].file;
@ -424,7 +434,7 @@ const useCustomerStore = defineStore('api-customer', () => {
); );
} }
async function fetchListBranchById( async function fetchListCustomeBranchById(
branchId: string, branchId: string,
flow?: { flow?: {
sessionId?: string; sessionId?: string;
@ -452,7 +462,7 @@ const useCustomerStore = defineStore('api-customer', () => {
getStatsCustomer, getStatsCustomer,
fetchListBranch, fetchListCustomeBranch,
fetchListById, fetchListById,
fetchList, fetchList,
create, create,
@ -461,7 +471,7 @@ const useCustomerStore = defineStore('api-customer', () => {
createBranch, createBranch,
editBranchById, editBranchById,
deleteBranchById, deleteBranchById,
fetchListBranchById, fetchListCustomeBranchById,
}; };
}); });