refactor: remove unnecessary param

This commit is contained in:
Methapon Metanipat 2024-08-28 11:29:59 +07:00
parent f9637e8b0e
commit 7fb103ede3

View file

@ -32,22 +32,15 @@ const useEmployeeStore = defineStore('api-employee', () => {
return false;
}
async function fetchList(
opts?: {
page?: number;
pageSize?: number;
query?: string;
gender?: string;
status?: Status;
zipCode?: string;
customerId?: string;
},
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
async function fetchList(opts?: {
page?: number;
pageSize?: number;
query?: string;
gender?: string;
status?: Status;
zipCode?: string;
customerId?: string;
}) {
const params = new URLSearchParams();
for (const [k, v] of Object.entries(opts || {})) {
@ -59,11 +52,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
const res = await api.get<Pagination<Employee[]>>(
`/employee${(params && '?'.concat(query)) || ''}`,
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
headers: { 'X-Rtid': flowStore.rtid },
},
);
@ -74,23 +63,12 @@ const useEmployeeStore = defineStore('api-employee', () => {
return false;
}
async function create(
data: EmployeeCreate,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
async function create(data: EmployeeCreate) {
const { id, code, image, ...payload } = data;
const res = await api.post<
Employee & { profileImageUrl: string; profileImageUploadUrl: string }
>('/employee', payload, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
headers: { 'X-Rtid': flowStore.rtid },
});
image &&
@ -109,23 +87,12 @@ const useEmployeeStore = defineStore('api-employee', () => {
async function createEmployeeCheckup(
employeeId: string,
data: EmployeeCheckupCreate,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const { id, statusSave, ...payload } = data;
const res = await api.post<EmployeeCheckupCreate>(
`/employee/${employeeId}/checkup`,
{ ...payload },
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
{ headers: { 'X-Rtid': flowStore.rtid } },
);
if (!res) return false;
@ -136,23 +103,12 @@ const useEmployeeStore = defineStore('api-employee', () => {
async function createEmployeeWork(
employeeId: string,
data: EmployeeWorkCreate,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const { id, ...payload } = data;
const res = await api.post<EmployeeWorkCreate>(
`/employee/${employeeId}/work`,
{ ...payload },
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
{ headers: { 'X-Rtid': flowStore.rtid } },
);
if (!res) return false;
@ -163,22 +119,13 @@ const useEmployeeStore = defineStore('api-employee', () => {
async function createEmployeeOtherInfo(
employeeId: string,
data: EmployeeOtherCreate,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const { id, statusSave, ...payload } = data;
const res = await api.post<EmployeeOtherCreate>(
`/employee/${employeeId}/other-info`,
{ ...payload },
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
headers: { 'X-Rtid': flowStore.rtid },
},
);
@ -190,11 +137,6 @@ const useEmployeeStore = defineStore('api-employee', () => {
async function editByIdEmployeeCheckup(
employeeOfId: string,
data: Partial<EmployeeCheckupCreate>,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const {
id,
@ -209,13 +151,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
const res = await api.put<EmployeeCheckupCreate>(
`/employee/${employeeOfId}/checkup/${id}`,
{ ...payload },
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
{ headers: { 'X-Rtid': flowStore.rtid } },
);
if (!res) return false;
@ -226,11 +162,6 @@ const useEmployeeStore = defineStore('api-employee', () => {
async function editByIdEmployeeWork(
employeeOfId: string,
data: Partial<EmployeeWorkCreate>,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const {
id,
@ -245,13 +176,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
const res = await api.put<EmployeeWorkCreate>(
`/employee/${employeeOfId}/work/${id}`,
{ ...payload },
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
{ headers: { 'X-Rtid': flowStore.rtid } },
);
if (!res) return false;
@ -262,11 +187,6 @@ const useEmployeeStore = defineStore('api-employee', () => {
async function editByIdEmployeeOtherInfo(
employeeOfId: string,
data: Partial<EmployeeOtherCreate>,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const {
id,
@ -281,13 +201,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
const res = await api.put<EmployeeOtherCreate>(
`/employee/${employeeOfId}/other-info/${id}`,
{ ...payload },
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
{ headers: { 'X-Rtid': flowStore.rtid } },
);
if (!res) return false;
@ -295,24 +209,12 @@ const useEmployeeStore = defineStore('api-employee', () => {
return res.data;
}
async function editById(
employeeId: string,
data: Partial<EmployeeCreate>,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
async function editById(employeeId: string, data: Partial<EmployeeCreate>) {
const { id, code, image, ...payload } = data;
const res = await api.put<
Employee & { imageUrl: string; profileImageUploadUrl: string }
>(`/employee/${employeeId}`, payload, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
headers: { 'X-Rtid': flowStore.rtid },
});
image &&
@ -328,26 +230,13 @@ const useEmployeeStore = defineStore('api-employee', () => {
return res.data;
}
async function deleteByIdCheckUp(
opts: {
employeeId: string;
checkUpId?: string;
},
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
async function deleteByIdCheckUp(opts: {
employeeId: string;
checkUpId?: string;
}) {
const res = await api.delete<Employee>(
`/employee/${opts.employeeId}/checkup/${opts.checkUpId}`,
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
{ headers: { 'X-Rtid': flowStore.rtid } },
);
if (!res) return false;
@ -356,25 +245,11 @@ const useEmployeeStore = defineStore('api-employee', () => {
return false;
}
async function deleteByIdWork(
opts: {
employeeId: string;
workId?: string;
},
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
async function deleteByIdWork(opts: { employeeId: string; workId?: string }) {
const res = await api.delete<Employee>(
`/employee/${opts.employeeId}/work/${opts.workId}`,
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
headers: { 'X-Rtid': flowStore.rtid },
},
);
@ -384,20 +259,9 @@ const useEmployeeStore = defineStore('api-employee', () => {
return false;
}
async function deleteById(
id: string,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
async function deleteById(id: string) {
const res = await api.delete<Employee>(`/employee/${id}`, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
headers: { 'X-Rtid': flowStore.rtid },
});
if (!res) return false;
@ -406,82 +270,38 @@ const useEmployeeStore = defineStore('api-employee', () => {
return false;
}
async function fetchCheckup(
id: string,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
async function fetchCheckup(id: string) {
const res = await api.get<EmployeeCheckup[]>(`/employee/${id}/checkup`, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
headers: { 'X-Rtid': flowStore.rtid },
});
if (res && res.status === 200) {
return res.data;
}
}
async function fetchWork(
id: string,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
async function fetchWork(id: string) {
const res = await api.get<EmployeeWork[]>(`/employee/${id}/work`, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
headers: { 'X-Rtid': flowStore.rtid },
});
if (res && res.status === 200) {
return res.data;
}
}
async function fetchOther(
id: string,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
async function fetchOther(id: string) {
const res = await api.get<EmployeeOther>(`/employee/${id}/other-info`, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
headers: { 'X-Rtid': flowStore.rtid },
});
if (res && res.status === 200) {
return res.data;
}
}
async function getStatsEmployee(
customerBranchId?: string,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
async function getStatsEmployee(customerBranchId?: string) {
const res = await api.get(
`/employee/stats${customerBranchId ? '?customerBranchId=' + customerBranchId : ''}/`,
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
headers: { 'X-Rtid': flowStore.rtid },
},
);
if (res && res.status === 200) {
@ -489,19 +309,11 @@ const useEmployeeStore = defineStore('api-employee', () => {
}
}
async function getStatsEmployeeGender(
opts?: {
customerBranchId?: string;
status?: 'CREATED' | 'ACTIVE' | 'INACTIVE';
query?: string;
},
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
async function getStatsEmployeeGender(opts?: {
customerBranchId?: string;
status?: 'CREATED' | 'ACTIVE' | 'INACTIVE';
query?: string;
}) {
const params = new URLSearchParams();
for (const [k, v] of Object.entries(opts || {})) {
@ -513,11 +325,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
const res = await api.get(
`/employee/stats/gender${(params && '?'.concat(query)) || ''}`,
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
headers: { 'X-Rtid': flowStore.rtid },
},
);
if (res && res.status === 200) {
@ -525,20 +333,9 @@ const useEmployeeStore = defineStore('api-employee', () => {
}
}
async function getEditHistory(
employeeId: string,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
async function getEditHistory(employeeId: string) {
const res = await api.get(`/employee/${employeeId}/edit-history`, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
headers: { 'X-Rtid': flowStore.rtid },
});
if (res && res.status === 200) {
return res.data;