feat: customer branch function + add

This commit is contained in:
oat_dev 2024-06-10 14:10:34 +07:00
parent aba1d61e01
commit 75246296ae
2 changed files with 95 additions and 2 deletions

View file

@ -30,6 +30,7 @@ import {
Customer,
CustomerUpdate,
CustomerBranch,
CustomerBranchCreate,
} from 'stores/customer/types';
import { onMounted } from 'vue';
import FormPerson from 'src/components/02_personnel-management/FormPerson.vue';
@ -38,8 +39,15 @@ import FormEmployeeHealthCheck from 'src/components/03_customer-management/FormE
import { dialog } from 'src/stores/utils';
const userCustomer = useCustomerStore();
const { create, getStatsCustomer, fetchList, editById, fetchListById } =
userCustomer;
const {
create,
getStatsCustomer,
fetchList,
editById,
fetchListById,
createBranch,
deleteBranchById,
} = userCustomer;
const formData = ref<CustomerCreate>({
status: 'CREATED',
customerType: 'CORP',
@ -302,6 +310,14 @@ async function onSubmit() {
async function onSubmitCustomerBranch() {
dialogInputCustomerBranchForm.value = false;
// await createBranch();
for (const item of formData.value.customerBranch || []) {
await createBranch({
...item,
customerId: currentCustomerId.value,
});
}
clearForm();
const result = await fetchListById(currentCustomerId.value);
if (result) {

View file

@ -10,6 +10,7 @@ import {
BranchAttachment,
CustomerStats,
CustomerBranch,
CustomerBranchCreate,
} from './types';
import axios from 'axios';
@ -231,6 +232,79 @@ const useCustomerStore = defineStore('api-customer', () => {
return false;
}
async function createBranch(
data: CustomerBranchCreate & { customerId: string },
flow?: {
sessionId: string;
refTransactionId: string;
transactionId: string;
},
) {
const res = await api.post<
Customer & {
branch: CustomerBranch[];
imageUrl: string;
imageUploadUrl: string;
}
>('/customer-branch', data, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId,
'X-Tid': flow?.transactionId,
},
});
if (!res) return false;
return res.data;
}
async function editBranchById(
id: string,
data: Partial<CustomerBranchCreate & { customerId: string }>,
flow?: {
sessionId: string;
refTransactionId: string;
transactionId: string;
},
) {
const res = await api.put<
Customer & {
branch: CustomerBranch[];
}
>(`'/customer-branch'/${id}`, data, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId,
'X-Tid': flow?.transactionId,
},
});
if (!res) return false;
return res.data;
}
async function deleteBranchById(
id: string,
flow?: {
sessionId: string;
refTransactionId: string;
transactionId: string;
},
) {
const res = await api.delete<Customer>(`/customer-branch/${id}`, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId,
'X-Tid': flow?.transactionId,
},
});
if (!res) return false;
if (res.status === 200) return res.data;
return false;
}
async function addBranchAttachment(
branchId: string,
payload: BranchAttachmentCreate,
@ -303,6 +377,9 @@ const useCustomerStore = defineStore('api-customer', () => {
create,
editById,
deleteById,
createBranch,
editBranchById,
deleteBranchById,
};
});