refactor: add api Checkup , Work , Other Info

This commit is contained in:
Net 2024-08-01 14:16:57 +07:00
parent f557fe3d4f
commit 355a30074c

View file

@ -95,6 +95,168 @@ const useEmployeeStore = defineStore('api-employee', () => {
return res.data;
}
async function createEmployeeCheckup(
employeeId: string,
data: EmployeeCreate,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const { code, image, ...payload } = data;
const res = await api.post<Employee>(
`/employee/${employeeId}/checkup`,
{ ...payload.employeeCheckup },
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
);
if (!res) return false;
return res.data;
}
async function createEmployeeWork(
employeeId: string,
data: EmployeeCreate,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const { code, image, ...payload } = data;
const res = await api.post<Employee>(
`/employee/${employeeId}/work`,
{ ...payload.employeeWork },
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
);
if (!res) return false;
return res.data;
}
async function createEmployeeOtherInfo(
employeeId: string,
data: EmployeeCreate,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const { code, image, ...payload } = data;
const res = await api.post<Employee>(
`/employee/${employeeId}/other-info`,
{ ...payload.employeeOtherInfo },
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
);
if (!res) return false;
return res.data;
}
async function editByIdEmployeeCheckup(
employeeId: string,
data: Partial<EmployeeCreate>,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const { code, image, ...payload } = data;
const res = await api.put<Employee>(
`/employee/${employeeId}/checkup}`,
{ ...payload.employeeCheckup },
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
);
if (!res) return false;
return res.data;
}
async function editByIdEmployeeWork(
employeeId: string,
data: Partial<EmployeeCreate>,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const { code, image, ...payload } = data;
const res = await api.put<Employee>(
`/employee/${employeeId}/work}`,
{ ...payload.employeeWork },
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
);
if (!res) return false;
return res.data;
}
async function editByIdEmployeeOtherInfo(
employeeId: string,
data: Partial<EmployeeCreate>,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const { code, image, ...payload } = data;
const res = await api.put<Employee>(
`/employee/${employeeId}/other-info}`,
{ ...payload.employeeWork },
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
);
if (!res) return false;
return res.data;
}
async function editById(
id: string,
data: Partial<EmployeeCreate>,
@ -304,6 +466,15 @@ const useEmployeeStore = defineStore('api-employee', () => {
getStatsEmployee,
getStatsEmployeeGender,
getEditHistory,
createEmployeeCheckup,
editByIdEmployeeCheckup,
createEmployeeWork,
editByIdEmployeeWork,
createEmployeeOtherInfo,
editByIdEmployeeOtherInfo,
};
});