chore: clean unused
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 7s

chore: clean unused
This commit is contained in:
Methapon2001 2025-03-26 15:26:01 +07:00
parent 1e9a5abc1c
commit 3646956038

View file

@ -15,12 +15,10 @@ import {
import axios from 'axios'; import axios from 'axios';
import useBranchStore from '../branch'; import useBranchStore from '../branch';
import { Branch } from '../branch/types'; import { Branch } from '../branch/types';
import useFlowStore from '../flow';
const branchStore = useBranchStore(); const branchStore = useBranchStore();
const useUserStore = defineStore('api-user', () => { const useUserStore = defineStore('api-user', () => {
const flowStore = useFlowStore();
const userOption = ref<UserOption>({ const userOption = ref<UserOption>({
hqOpts: [], hqOpts: [],
brOpts: [], brOpts: [],
@ -95,37 +93,15 @@ const useUserStore = defineStore('api-user', () => {
}); });
} }
async function fetchAttachment( async function fetchAttachment(userId: string) {
userId: string, const res = await api.get<UserAttachment[]>(`/user/${userId}/attachment`);
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const res = await api.get<UserAttachment[]>(`/user/${userId}/attachment`, {
headers: {
'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;
} }
return false; return false;
} }
async function addAttachment( async function addAttachment(userId: string, payload: UserAttachmentCreate) {
userId: string,
payload: UserAttachmentCreate,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const list: { name: string; file: File }[] = []; const list: { name: string; file: File }[] = [];
payload.file.forEach((v) => { payload.file.forEach((v) => {
@ -156,13 +132,6 @@ const useUserStore = defineStore('api-user', () => {
const res = await api.post<(UserAttachment & { uploadUrl: string })[]>( const res = await api.post<(UserAttachment & { uploadUrl: string })[]>(
`/user/${userId}/attachment`, `/user/${userId}/attachment`,
{ file: list.map((v) => v.name) }, { file: list.map((v) => v.name) },
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
); );
await Promise.all( await Promise.all(
@ -182,19 +151,9 @@ const useUserStore = defineStore('api-user', () => {
async function deleteAttachment( async function deleteAttachment(
userId: string, userId: string,
payload: UserAttachmentDelete, payload: UserAttachmentDelete,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) { ) {
await api.delete(`/user/${userId}/attachment`, { await api.delete(`/user/${userId}/attachment`, {
data: payload, data: payload,
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
}); });
} }
@ -217,21 +176,8 @@ const useUserStore = defineStore('api-user', () => {
return false; return false;
} }
async function fetchById( async function fetchById(id: string) {
id: string, const res = await api.get<User>(`/user/${id}`);
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const res = await api.get<User>(`/user/${id}`, {
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;
@ -240,21 +186,8 @@ const useUserStore = defineStore('api-user', () => {
return false; return false;
} }
async function fetchImageListById( async function fetchImageListById(id: string) {
id: string, const res = await api.get(`/user/${id}/profile-image`);
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const res = await api.get(`/user/${id}/profile-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;
@ -274,22 +207,8 @@ const useUserStore = defineStore('api-user', () => {
return name; return name;
} }
async function deleteImageByName( async function deleteImageByName(id: string, name: string) {
id: string, const res = await api.delete(`/user/${id}/profile-image/${name}`);
name: string,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const res = await api.delete(`/user/${id}/profile-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;
} }
@ -300,27 +219,12 @@ const useUserStore = defineStore('api-user', () => {
selectedImage: string; selectedImage: string;
list: { url: string; imgFile: File | null; name: string }[]; list: { url: string; imgFile: File | null; name: string }[];
}, },
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) { ) {
const { zipCode, ...payload } = data; const { zipCode, ...payload } = data;
const res = await api.post<User>( const res = await api.post<User>('/user', {
'/user', ...payload,
{ selectedImage: imgList.selectedImage || '',
...payload, });
selectedImage: imgList.selectedImage || '',
},
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
);
if (imgList.list.length > 0 && res.data.id) { if (imgList.list.length > 0 && res.data.id) {
for (let index = 0; index < imgList.list.length; index++) { for (let index = 0; index < imgList.list.length; index++) {
@ -338,42 +242,18 @@ const useUserStore = defineStore('api-user', () => {
async function editById( async function editById(
id: string, id: string,
data: Partial<UserCreate & { status?: 'ACTIVE' | 'INACTIVE' }>, data: Partial<UserCreate & { status?: 'ACTIVE' | 'INACTIVE' }>,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) { ) {
const { zipCode, ...paylond } = data; const { zipCode, ...payload } = data;
const res = await api.put<User>(`/user/${id}`, paylond, { const res = await api.put<User>(`/user/${id}`, payload);
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
});
if (!res) return false; if (!res) return false;
return res.data; return res.data;
} }
async function deleteById( async function deleteById(id: string) {
id: string, const res = await api.delete<User>(`/user/${id}`);
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const res = await api.delete<User>(`/user/${id}`, {
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;
@ -381,21 +261,8 @@ const useUserStore = defineStore('api-user', () => {
return false; return false;
} }
async function getBranch( async function getBranch(userId: string) {
userId: string, const res = await api.get<Pagination<Branch[]>>(`/user/${userId}/branch`);
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const res = await api.get<Pagination<Branch[]>>(`/user/${userId}/branch`, {
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;
@ -403,26 +270,10 @@ const useUserStore = defineStore('api-user', () => {
return false; return false;
} }
async function addBranch( async function addBranch(userId: string, branchId: string | string[]) {
userId: string, const res = await api.post(`/user/${userId}/branch`, {
branchId: string | string[], branch: ([] as string[]).concat(branchId),
flow?: { });
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const res = await api.post(
`/user/${userId}/branch`,
{ branch: ([] as string[]).concat(branchId) },
{
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 >= 400) return false; if (res.status >= 400) return false;
@ -430,21 +281,8 @@ const useUserStore = defineStore('api-user', () => {
return res.data || true; return res.data || true;
} }
async function removeBranch( async function removeBranch(userId: string, branchId: string | string[]) {
userId: string,
branchId: string | string[],
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const res = await api.delete(`/user/${userId}/branch`, { const res = await api.delete(`/user/${userId}/branch`, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
data: { branch: ([] as string[]).concat(branchId) }, data: { branch: ([] as string[]).concat(branchId) },
}); });
@ -454,18 +292,8 @@ const useUserStore = defineStore('api-user', () => {
return res.data || true; return res.data || true;
} }
async function typeStats(flow?: { async function typeStats() {
sessionId?: string; const res = await api.get('/user/type-stats');
refTransactionId?: string;
transactionId?: string;
}) {
const res = await api.get('/user/type-stats', {
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;