feat: implement API composables for authentication and data fetching
- Add useApiFetch composable for HTTP requests with auth token - Implement useAuth composable for authentication endpoints - Add useAdmin composable for admin operations - Add useOperator composable for operator management - Add useMembers composable for member data - Add usePublic composable for public reports - Add useReports composable for report operations Co-authored-by: Copilot <[email protected]>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import type {
|
||||
AreaListResponse, CategoryListResponse, CreateAreaRequest, CreateCategoryRequest, CreateTeamRequest,
|
||||
ModerationListResponse,
|
||||
OkResponse,
|
||||
OverviewStatsResponse, TeamListResponse, UpdateModerationRequest,
|
||||
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/admin/areas', { method: 'GET' })
|
||||
|
||||
const createArea = (body: CreateAreaRequest) =>
|
||||
useApiFetch<OkResponse>('/api/v1/admin/areas', { method: 'POST', 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 getTeams = () =>
|
||||
useApiFetch<TeamListResponse>('/api/v1/admin/teams', { method: 'GET' })
|
||||
|
||||
const createTeam = (body: CreateTeamRequest) =>
|
||||
useApiFetch<OkResponse>('/api/v1/admin/teams', { method: 'POST', 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,
|
||||
getCategories,
|
||||
createCategory,
|
||||
getTeams,
|
||||
createTeam,
|
||||
getModerationFlags,
|
||||
updateModerationFlag,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user