133 lines
3.6 KiB
TypeScript
133 lines
3.6 KiB
TypeScript
/**
|
|
* Admin API
|
|
*
|
|
* Dedicated endpoints for admin-only operations that return ALL data from the database
|
|
* without organization filtering.
|
|
*
|
|
* All endpoints require ADMIN role.
|
|
*/
|
|
|
|
import { get, post, patch, del } from './client';
|
|
import type {
|
|
UserResponse,
|
|
UserListResponse,
|
|
OrganizationResponse,
|
|
OrganizationListResponse,
|
|
BookingResponse,
|
|
BookingListResponse,
|
|
UpdateUserRequest,
|
|
} from '@/types/api';
|
|
|
|
// ==================== USERS ====================
|
|
|
|
/**
|
|
* Get ALL users from database (admin only)
|
|
* GET /api/v1/admin/users
|
|
* Returns all users regardless of status or organization
|
|
* Requires: ADMIN role
|
|
*/
|
|
export async function getAllUsers(): Promise<UserListResponse> {
|
|
return get<UserListResponse>('/api/v1/admin/users');
|
|
}
|
|
|
|
/**
|
|
* Get user by ID (admin only)
|
|
* GET /api/v1/admin/users/:id
|
|
* Requires: ADMIN role
|
|
*/
|
|
export async function getAdminUser(id: string): Promise<UserResponse> {
|
|
return get<UserResponse>(`/api/v1/admin/users/${id}`);
|
|
}
|
|
|
|
/**
|
|
* Update user (admin only)
|
|
* PATCH /api/v1/admin/users/:id
|
|
* Can update any user from any organization
|
|
* Requires: ADMIN role
|
|
*/
|
|
export async function updateAdminUser(id: string, data: UpdateUserRequest): Promise<UserResponse> {
|
|
return patch<UserResponse>(`/api/v1/admin/users/${id}`, data);
|
|
}
|
|
|
|
/**
|
|
* Delete user (admin only)
|
|
* DELETE /api/v1/admin/users/:id
|
|
* Permanently deletes user from database
|
|
* Requires: ADMIN role
|
|
*/
|
|
export async function deleteAdminUser(id: string): Promise<void> {
|
|
return del<void>(`/api/v1/admin/users/${id}`);
|
|
}
|
|
|
|
// ==================== ORGANIZATIONS ====================
|
|
|
|
/**
|
|
* Get ALL organizations from database (admin only)
|
|
* GET /api/v1/admin/organizations
|
|
* Returns all organizations regardless of status
|
|
* Requires: ADMIN role
|
|
*/
|
|
export async function getAllOrganizations(): Promise<OrganizationListResponse> {
|
|
return get<OrganizationListResponse>('/api/v1/admin/organizations');
|
|
}
|
|
|
|
/**
|
|
* Get organization by ID (admin only)
|
|
* GET /api/v1/admin/organizations/:id
|
|
* Requires: ADMIN role
|
|
*/
|
|
export async function getAdminOrganization(id: string): Promise<OrganizationResponse> {
|
|
return get<OrganizationResponse>(`/api/v1/admin/organizations/${id}`);
|
|
}
|
|
|
|
// ==================== BOOKINGS ====================
|
|
|
|
/**
|
|
* Get ALL bookings from database (admin only)
|
|
* GET /api/v1/admin/bookings
|
|
* Returns all bookings from all organizations
|
|
* Requires: ADMIN role
|
|
*/
|
|
export async function getAllBookings(): Promise<BookingListResponse> {
|
|
return get<BookingListResponse>('/api/v1/admin/bookings');
|
|
}
|
|
|
|
/**
|
|
* Get booking by ID (admin only)
|
|
* GET /api/v1/admin/bookings/:id
|
|
* Requires: ADMIN role
|
|
*/
|
|
export async function getAdminBooking(id: string): Promise<BookingResponse> {
|
|
return get<BookingResponse>(`/api/v1/admin/bookings/${id}`);
|
|
}
|
|
|
|
// ==================== DOCUMENTS ====================
|
|
|
|
/**
|
|
* Get ALL documents from all organizations (admin only)
|
|
* GET /api/v1/admin/documents
|
|
* Returns documents grouped by organization
|
|
* Requires: ADMIN role
|
|
*/
|
|
export async function getAllDocuments(): Promise<{
|
|
documents: any[];
|
|
total: number;
|
|
organizationCount: number;
|
|
}> {
|
|
return get('/api/v1/admin/documents');
|
|
}
|
|
|
|
/**
|
|
* Get documents for a specific organization (admin only)
|
|
* GET /api/v1/admin/organizations/:id/documents
|
|
* Requires: ADMIN role
|
|
*/
|
|
export async function getOrganizationDocuments(organizationId: string): Promise<{
|
|
organizationId: string;
|
|
organizationName: string;
|
|
documents: any[];
|
|
total: number;
|
|
}> {
|
|
return get(`/api/v1/admin/organizations/${organizationId}/documents`);
|
|
}
|