feat: remove flow from store

This commit is contained in:
Methapon Metanipat 2024-10-29 08:54:07 +07:00
parent 0c3eeef35e
commit 98b4771a52

View file

@ -19,7 +19,6 @@ import useFlowStore from '../flow';
import { baseUrl, manageFile, manageMeta } from '../utils'; import { baseUrl, manageFile, manageMeta } from '../utils';
const useEmployeeStore = defineStore('api-employee', () => { const useEmployeeStore = defineStore('api-employee', () => {
const flowStore = useFlowStore();
const data = ref<Pagination<Employee[]>>(); const data = ref<Pagination<Employee[]>>();
const globalOption = ref(); const globalOption = ref();
const ownerOption = ref<CustomerBranch[]>(); const ownerOption = ref<CustomerBranch[]>();
@ -62,21 +61,8 @@ const useEmployeeStore = defineStore('api-employee', () => {
return false; return false;
} }
async function fetchImageListById( async function fetchImageListById(id: string) {
id: string, const res = await api.get(`/employee/${id}/image`);
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const res = await api.get(`/employee/${id}/image`, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
});
if (!res) return false; if (!res) return false;
if (res.status === 200) return res.data; if (res.status === 200) return res.data;
@ -96,22 +82,8 @@ const useEmployeeStore = defineStore('api-employee', () => {
return name; return name;
} }
async function deleteImageByName( async function deleteImageByName(id: string, name: string) {
id: string, const res = await api.delete(`/employee/${id}/image/${name}`);
name: string,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const res = await api.delete(`/employee/${id}/image/${name}`, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
});
if (!res) return false; if (!res) return false;
} }
@ -137,13 +109,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
} = data; } = data;
const res = await api.post< const res = await api.post<
Employee & { profileImageUrl: string; profileImageUploadUrl: string } Employee & { profileImageUrl: string; profileImageUploadUrl: string }
>( >('/employee', { ...payload, selectedImage: imgList.selectedImage });
'/employee',
{ ...payload, selectedImage: imgList.selectedImage },
{
headers: { 'X-Rtid': flowStore.rtid },
},
);
if (!res) return false; if (!res) return false;
@ -197,7 +163,6 @@ const useEmployeeStore = defineStore('api-employee', () => {
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 } },
); );
if (!res) return false; if (!res) return false;
@ -213,7 +178,6 @@ const useEmployeeStore = defineStore('api-employee', () => {
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 } },
); );
if (!res) return false; if (!res) return false;
@ -229,9 +193,6 @@ const useEmployeeStore = defineStore('api-employee', () => {
const res = await api.post<EmployeeOtherCreate>( const res = await api.post<EmployeeOtherCreate>(
`/employee/${employeeId}/other-info`, `/employee/${employeeId}/other-info`,
{ ...payload }, { ...payload },
{
headers: { 'X-Rtid': flowStore.rtid },
},
); );
if (!res) return false; if (!res) return false;
@ -256,7 +217,6 @@ 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 } },
); );
if (!res) return false; if (!res) return false;
@ -281,7 +241,6 @@ 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 } },
); );
if (!res) return false; if (!res) return false;
@ -307,7 +266,6 @@ 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 } },
); );
if (!res) return false; if (!res) return false;
@ -330,9 +288,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
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: { 'X-Rtid': flowStore.rtid },
});
if (!res) return false; if (!res) return false;
@ -361,7 +317,6 @@ const useEmployeeStore = defineStore('api-employee', () => {
}) { }) {
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 } },
); );
if (!res) return false; if (!res) return false;
@ -373,9 +328,6 @@ const useEmployeeStore = defineStore('api-employee', () => {
async function deleteByIdWork(opts: { employeeId: string; workId?: string }) { async function deleteByIdWork(opts: { employeeId: string; workId?: 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: { 'X-Rtid': flowStore.rtid },
},
); );
if (!res) return false; if (!res) return false;
@ -385,9 +337,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
} }
async function deleteById(id: string) { async function deleteById(id: string) {
const res = await api.delete<Employee>(`/employee/${id}`, { const res = await api.delete<Employee>(`/employee/${id}`);
headers: { 'X-Rtid': flowStore.rtid },
});
if (!res) return false; if (!res) return false;
if (res.status === 200) return res.data; if (res.status === 200) return res.data;
@ -396,27 +346,21 @@ const useEmployeeStore = defineStore('api-employee', () => {
} }
async function fetchCheckup(id: string) { async function fetchCheckup(id: string) {
const res = await api.get<EmployeeCheckup[]>(`/employee/${id}/checkup`, { const res = await api.get<EmployeeCheckup[]>(`/employee/${id}/checkup`);
headers: { 'X-Rtid': flowStore.rtid },
});
if (res && res.status === 200) { if (res && res.status === 200) {
return res.data; return res.data;
} }
} }
async function fetchWork(id: string) { async function fetchWork(id: string) {
const res = await api.get<EmployeeWork[]>(`/employee/${id}/work`, { const res = await api.get<EmployeeWork[]>(`/employee/${id}/work`);
headers: { 'X-Rtid': flowStore.rtid },
});
if (res && res.status === 200) { if (res && res.status === 200) {
return res.data; return res.data;
} }
} }
async function fetchOther(id: string) { async function fetchOther(id: string) {
const res = await api.get<EmployeeOther>(`/employee/${id}/other-info`, { const res = await api.get<EmployeeOther>(`/employee/${id}/other-info`);
headers: { 'X-Rtid': flowStore.rtid },
});
if (res && res.status === 200) { if (res && res.status === 200) {
return res.data; return res.data;
} }
@ -425,9 +369,6 @@ const useEmployeeStore = defineStore('api-employee', () => {
async function getStatsEmployee(customerBranchId?: string) { async function getStatsEmployee(customerBranchId?: string) {
const res = await api.get( const res = await api.get(
`/employee/stats${customerBranchId ? '?customerBranchId=' + customerBranchId : ''}/`, `/employee/stats${customerBranchId ? '?customerBranchId=' + customerBranchId : ''}/`,
{
headers: { 'X-Rtid': flowStore.rtid },
},
); );
if (res && res.status === 200) { if (res && res.status === 200) {
return res.data; return res.data;
@ -449,9 +390,6 @@ 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: { 'X-Rtid': flowStore.rtid },
},
); );
if (res && res.status === 200) { if (res && res.status === 200) {
return res.data; return res.data;
@ -459,9 +397,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
} }
async function getEditHistory(employeeId: string) { async function getEditHistory(employeeId: string) {
const res = await api.get(`/employee/${employeeId}/edit-history`, { const res = await api.get(`/employee/${employeeId}/edit-history`);
headers: { 'X-Rtid': flowStore.rtid },
});
if (res && res.status === 200) { if (res && res.status === 200) {
return res.data; return res.data;
} }
@ -501,12 +437,6 @@ const useEmployeeStore = defineStore('api-employee', () => {
const res = await api.put( const res = await api.put(
`/employee/${employeeId}/attachment/${filename || file.name}`, `/employee/${employeeId}/attachment/${filename || file.name}`,
file, file,
{
headers: {
'X-Rtid': flowStore.rtid,
'Content-Type': file.type,
},
},
); );
return !(!res || res.status >= 400); return !(!res || res.status >= 400);
} }
@ -514,7 +444,6 @@ const useEmployeeStore = defineStore('api-employee', () => {
async function deleteAttachment(employeeId: string, filename: string) { async function deleteAttachment(employeeId: string, filename: string) {
const res = await api.delete( const res = await api.delete(
`/employee/${employeeId}/attachment/${filename}`, `/employee/${employeeId}/attachment/${filename}`,
{ headers: { 'X-Rtid': flowStore.rtid } },
); );
return !(!res || res.status >= 400); return !(!res || res.status >= 400);
} }
@ -532,9 +461,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
} }
async function listPassport(employeeId: string) { async function listPassport(employeeId: string) {
const res = await api.get(`/employee/${employeeId}/passport`, { const res = await api.get(`/employee/${employeeId}/passport`);
headers: { 'X-Rtid': flowStore.rtid },
});
if (res && res.status < 400) return res.data; if (res && res.status < 400) return res.data;