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