75 lines
2.7 KiB
TypeScript
75 lines
2.7 KiB
TypeScript
import type {
|
|
AreaListResponse, CategoryListResponse, CreateAreaRequest, CreateCategoryRequest, CreateTeamRequest,
|
|
ModerationListResponse,
|
|
OkResponse,
|
|
OverviewStatsResponse, TeamListResponse, UpdateModerationRequest,
|
|
UpdateAreaRequest, UpdateCategoryRequest, UpdateTeamRequest,
|
|
UpdateUserBanRequest, UpdateUserRolesRequest,
|
|
UserListResponse
|
|
} from "~/types/api";
|
|
|
|
export const useAdmin = () => {
|
|
const getOverviewStats = () =>
|
|
useApiFetch<OverviewStatsResponse>('/api/v1/admin/stats/overview', { method: 'GET' })
|
|
|
|
const getUsers = () =>
|
|
useApiFetch<UserListResponse>('/api/v1/admin/users', { method: 'GET' })
|
|
|
|
const updateUserBan = (id: number, body: UpdateUserBanRequest) =>
|
|
useApiFetch<OkResponse>(`/api/v1/admin/users/${id}/ban`, { method: 'PATCH', body })
|
|
|
|
const updateUserRoles = (id: number, body: UpdateUserRolesRequest) =>
|
|
useApiFetch<OkResponse>(`/api/v1/admin/users/${id}/roles`, { method: 'PATCH', body })
|
|
|
|
const getAreas = () =>
|
|
useApiFetch<AreaListResponse>('/api/v1/areas', { method: 'GET' })
|
|
|
|
const createArea = (body: CreateAreaRequest) =>
|
|
useApiFetch<OkResponse>('/api/v1/admin/areas', { method: 'POST', body })
|
|
|
|
const updateArea = (id: number, body: UpdateAreaRequest) =>
|
|
useApiFetch<OkResponse>(`/api/v1/admin/areas/${id}`, { method: 'PATCH', body })
|
|
|
|
const getCategories = () =>
|
|
useApiFetch<CategoryListResponse>('/api/v1/admin/categories', { method: 'GET' })
|
|
|
|
const createCategory = (body: CreateCategoryRequest) =>
|
|
useApiFetch<OkResponse>('/api/v1/admin/categories', { method: 'POST', body })
|
|
|
|
const updateCategory = (id: number, body: UpdateCategoryRequest) =>
|
|
useApiFetch<OkResponse>(`/api/v1/admin/categories/${id}`, { method: 'PATCH', body })
|
|
|
|
const getTeams = () =>
|
|
useApiFetch<TeamListResponse>('/api/v1/admin/teams', { method: 'GET' })
|
|
|
|
const createTeam = (body: CreateTeamRequest) =>
|
|
useApiFetch<OkResponse>('/api/v1/admin/teams', { method: 'POST', body })
|
|
|
|
const updateTeam = (id: number, body: UpdateTeamRequest) =>
|
|
useApiFetch<OkResponse>(`/api/v1/admin/teams/${id}`, { method: 'PATCH', body })
|
|
|
|
const getModerationFlags = (query?: { status?: string; page?: number; per_page?: number }) =>
|
|
useApiFetch<ModerationListResponse>('/api/v1/admin/moderation', { method: 'GET', query })
|
|
|
|
const updateModerationFlag = (id: number, body: UpdateModerationRequest) =>
|
|
useApiFetch<OkResponse>(`/api/v1/admin/moderation/${id}`, { method: 'PATCH', body })
|
|
|
|
return {
|
|
getOverviewStats,
|
|
getUsers,
|
|
updateUserBan,
|
|
updateUserRoles,
|
|
getAreas,
|
|
createArea,
|
|
updateArea,
|
|
getCategories,
|
|
createCategory,
|
|
updateCategory,
|
|
getTeams,
|
|
createTeam,
|
|
updateTeam,
|
|
getModerationFlags,
|
|
updateModerationFlag,
|
|
}
|
|
}
|