delete admin

This commit is contained in:
2026-05-13 13:31:18 +03:30
parent 2bef84e089
commit f994a61567
4 changed files with 84 additions and 14 deletions
+53 -3
View File
@@ -1,6 +1,6 @@
import useAxios from '@core/utils/useAxios'
import type { AddId, User } from '@/model/user'
import type { TableInput } from '@core/type/baseTable'
import type { TableInput, TableOutput } from '@core/type/baseTable'
import type {Referrals} from '@/model/referrals'
import type {Funds} from "@/model/funds";
@@ -23,8 +23,58 @@ export const updateUser = async (id: number, obj: User) =>
export const deleteUser = async (id: number) => await useAxios.delete(`/admin/user/${id}`)
export const getUserTable = async (params: TableInput) =>
await useAxios.post<Array<User>>('/admin/user/table', params)
function isUserTableOutput(data: unknown): data is TableOutput<User> {
if (data === null || typeof data !== 'object') return false
const d = data as Record<string, unknown>
return Array.isArray(d.rows) && d.query !== null && typeof d.query === 'object'
}
/** BaseTable expects `{ rows, query }`; backend may return a plain array or Laravel paginator. */
export const getUserTable = async (params: TableInput): Promise<TableOutput<User>> => {
const raw = await useAxios.post<unknown>('/admin/user/table', params)
if (isUserTableOutput(raw)) {
return raw
}
// Laravel LengthAwarePaginator
if (raw && typeof raw === 'object' && Array.isArray((raw as { data?: unknown }).data)) {
const r = raw as {
data: User[]
current_page?: number
per_page?: number
total?: number
}
return {
rows: r.data,
query: {
...params,
page: r.current_page ?? params.page,
limit: r.per_page ?? params.limit,
total: r.total ?? r.data.length
}
}
}
if (Array.isArray(raw)) {
return {
rows: raw as User[],
query: { ...params, total: raw.length }
}
}
if (raw && typeof raw === 'object' && Array.isArray((raw as { rows?: User[] }).rows)) {
const r = raw as { rows: User[]; total?: number }
return {
rows: r.rows,
query: { ...params, total: r.total ?? r.rows.length }
}
}
const users = (raw as { users?: User[] })?.users
if (Array.isArray(users)) {
return {
rows: users,
query: { ...params, total: users.length }
}
}
return { rows: [], query: { ...params, total: 0 } }
}
export const changeUserActivation = async (id: number) =>
await useAxios.get(`/admin/user/active/${id}`)