fix/feat: type and update function

This commit is contained in:
puriphatt 2024-06-12 08:40:30 +00:00
parent 46a7f9ca96
commit ad942e7035
2 changed files with 75 additions and 3 deletions

View file

@ -2,7 +2,14 @@ import { ref } from 'vue';
import { defineStore } from 'pinia';
import { Pagination } from '../types';
import { api } from 'src/boot/axios';
import { Employee, EmployeeCreate, EmployeeUpdate } from './types';
import {
Employee,
EmployeeCheckup,
EmployeeCreate,
EmployeeOther,
EmployeeUpdate,
EmployeeWork,
} from './types';
import axios from 'axios';
const useEmployeeStore = defineStore('api-employee', () => {
@ -84,7 +91,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
async function editById(
id: string,
data: EmployeeUpdate,
data: EmployeeCreate,
flow?: {
sessionId: string;
refTransactionId: string;
@ -137,6 +144,66 @@ const useEmployeeStore = defineStore('api-employee', () => {
return false;
}
async function fetchCheckup(
id: string,
flow?: {
sessionId: string;
refTransactionId: string;
transactionId: string;
},
) {
const res = await api.get<EmployeeCheckup[]>(`/employee/${id}/checkup`, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId,
'X-Tid': flow?.transactionId,
},
});
if (res && res.status === 200) {
return res.data;
}
}
async function fetchWork(
id: string,
flow?: {
sessionId: string;
refTransactionId: string;
transactionId: string;
},
) {
const res = await api.get<EmployeeWork[]>(`/employee/${id}/work`, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId,
'X-Tid': flow?.transactionId,
},
});
if (res && res.status === 200) {
return res.data;
}
}
async function fetchOther(
id: string,
flow?: {
sessionId: string;
refTransactionId: string;
transactionId: string;
},
) {
const res = await api.get<EmployeeOther>(`/employee/${id}/other-info`, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId,
'X-Tid': flow?.transactionId,
},
});
if (res && res.status === 200) {
return res.data;
}
}
return {
data,
globalOption,
@ -146,6 +213,9 @@ const useEmployeeStore = defineStore('api-employee', () => {
create,
editById,
deleteById,
fetchCheckup,
fetchWork,
fetchOther,
};
});

View file

@ -35,6 +35,7 @@ export type Employee = {
customerBranchId: string;
status: Status;
tm6Number: string;
entryDate: Date;
createdAt: Date;
createdBy: string;
updatedAt: Date;
@ -187,7 +188,7 @@ export type EmployeeWorkCreate = {
};
export type EmployeeOther = {
birthPlace: string;
motherBirthPlace: string;
motherLastNameEN: string;
motherFirstNameEN: string;
fatherLastNameEN: string;
@ -196,6 +197,7 @@ export type EmployeeOther = {
motherFirstName: string;
fatherLastName: string;
fatherFirstName: string;
fatherBirthPlace: string;
citizenId: string;
};