refactor: add delete

This commit is contained in:
Net 2024-08-01 16:44:13 +07:00
parent 9618085ac4
commit ae5f66eaa4
2 changed files with 115 additions and 2 deletions

View file

@ -921,6 +921,41 @@ function deleteBranchId(id: string) {
// flowStore.rotate();
// }
async function deleteByIdCheckOrwork(
id: string,
type: 'healthCheck' | 'workHistory',
indexTab: number,
) {
dialog({
color: 'info',
icon: 'mdi-alert',
title: t('saveConfirmTitle'),
actionText: t('ok'),
persistent: true,
message: t('saveConfirmMessage'),
action: async () => {
if (type === 'healthCheck') {
await employeeStore.deleteByIdCheckUp({
employeeId: currentEmployeeId.value,
checkUpId: id,
});
formDataEmployee.value.employeeCheckup?.splice(indexTab, 1);
}
if (type === 'workHistory') {
await employeeStore.deleteByIdWork({
employeeId: currentEmployeeId.value,
workId: id,
});
}
flowStore.rotate();
},
cancel: () => {},
});
}
async function onSubmitEmployee(
type: 'personalInfo' | 'healthCheck' | 'workHistory' | 'other',
indexTab: number = 0,
@ -967,6 +1002,7 @@ async function onSubmitEmployee(
);
if (res) {
formDataEmployee.value.employeeCheckup[indexTab].id = res.id;
formDataEmployee.value.employeeCheckup[indexTab].statusSave = true;
}
}
@ -983,6 +1019,7 @@ async function onSubmitEmployee(
);
if (res) {
formDataEmployee.value.employeeWork[indexTab].id = res.id;
formDataEmployee.value.employeeWork[indexTab].statusSave = true;
}
}
@ -3476,6 +3513,15 @@ watch(isMainPage, () => {
onSubmitEmployee('healthCheck', index);
}
"
@remove="
(index) => {
deleteByIdCheckOrwork(
formDataEmployee.employeeCheckup?.[index].id || '',
'healthCheck',
index,
);
}
"
/>
<FormEmployeeWorkHistory
prefix-id="form-dialog"
@ -3492,6 +3538,15 @@ watch(isMainPage, () => {
onSubmitEmployee('workHistory', index);
}
"
@remove="
(index) => {
deleteByIdCheckOrwork(
formDataEmployee.employeeWork?.[index].id || '',
'healthCheck',
index,
);
}
"
/>
<FormEmployeeOther
prefix-id="form-dialog"

View file

@ -107,7 +107,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
transactionId?: string;
},
) {
const { ...payload } = data;
const { id, ...payload } = data;
const res = await api.post<EmployeeCheckupCreate>(
`/employee/${employeeId}/checkup`,
{ ...payload },
@ -134,7 +134,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
transactionId?: string;
},
) {
const { ...payload } = data;
const { id, ...payload } = data;
const res = await api.post<EmployeeWorkCreate>(
`/employee/${employeeId}/work`,
{ ...payload },
@ -293,6 +293,62 @@ const useEmployeeStore = defineStore('api-employee', () => {
return res.data;
}
async function deleteByIdCheckUp(
opt: {
employeeId: string;
checkUpId?: string;
},
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const res = await api.delete<Employee>(
`/employee/${opt.employeeId}/checkup/${opt.checkUpId}`,
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
);
if (!res) return false;
if (res.status === 200) return res.data;
return false;
}
async function deleteByIdWork(
opt: {
employeeId: string;
workId?: string;
},
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const res = await api.delete<Employee>(
`/employee/${opt.employeeId}/work/${opt.workId}`,
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
);
if (!res) return false;
if (res.status === 200) return res.data;
return false;
}
async function deleteById(
id: string,
flow?: {
@ -472,9 +528,11 @@ const useEmployeeStore = defineStore('api-employee', () => {
createEmployeeCheckup,
editByIdEmployeeCheckup,
deleteByIdCheckUp,
createEmployeeWork,
editByIdEmployeeWork,
deleteByIdWork,
createEmployeeOtherInfo,
editByIdEmployeeOtherInfo,