Admin User v1
This commit is contained in:
182
frontend/src/features/admin/api/admin.api.ts
Normal file
182
frontend/src/features/admin/api/admin.api.ts
Normal file
@@ -0,0 +1,182 @@
|
||||
/**
|
||||
* @ai-summary API client functions for admin feature
|
||||
* @ai-context Communicates with backend admin endpoints
|
||||
*/
|
||||
|
||||
import { apiClient } from '../../../core/api/client';
|
||||
import {
|
||||
AdminAccessResponse,
|
||||
AdminUser,
|
||||
CreateAdminRequest,
|
||||
AdminAuditLog,
|
||||
CatalogMake,
|
||||
CatalogModel,
|
||||
CatalogYear,
|
||||
CatalogTrim,
|
||||
CatalogEngine,
|
||||
CreateCatalogMakeRequest,
|
||||
UpdateCatalogMakeRequest,
|
||||
CreateCatalogModelRequest,
|
||||
UpdateCatalogModelRequest,
|
||||
CreateCatalogYearRequest,
|
||||
CreateCatalogTrimRequest,
|
||||
UpdateCatalogTrimRequest,
|
||||
CreateCatalogEngineRequest,
|
||||
UpdateCatalogEngineRequest,
|
||||
StationOverview,
|
||||
CreateStationRequest,
|
||||
UpdateStationRequest,
|
||||
} from '../types/admin.types';
|
||||
|
||||
// Admin access verification
|
||||
export const adminApi = {
|
||||
// Verify admin access
|
||||
verifyAccess: async (): Promise<AdminAccessResponse> => {
|
||||
const response = await apiClient.get<AdminAccessResponse>('/admin/verify');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// Admin management
|
||||
listAdmins: async (): Promise<AdminUser[]> => {
|
||||
const response = await apiClient.get<AdminUser[]>('/admin/admins');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
createAdmin: async (data: CreateAdminRequest): Promise<AdminUser> => {
|
||||
const response = await apiClient.post<AdminUser>('/admin/admins', data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
revokeAdmin: async (auth0Sub: string): Promise<void> => {
|
||||
await apiClient.patch(`/admin/admins/${auth0Sub}/revoke`);
|
||||
},
|
||||
|
||||
reinstateAdmin: async (auth0Sub: string): Promise<void> => {
|
||||
await apiClient.patch(`/admin/admins/${auth0Sub}/reinstate`);
|
||||
},
|
||||
|
||||
// Audit logs
|
||||
listAuditLogs: async (): Promise<AdminAuditLog[]> => {
|
||||
const response = await apiClient.get<AdminAuditLog[]>('/admin/audit-logs');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// Catalog - Makes
|
||||
listMakes: async (): Promise<CatalogMake[]> => {
|
||||
const response = await apiClient.get<CatalogMake[]>('/admin/catalog/makes');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
createMake: async (data: CreateCatalogMakeRequest): Promise<CatalogMake> => {
|
||||
const response = await apiClient.post<CatalogMake>('/admin/catalog/makes', data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
updateMake: async (id: string, data: UpdateCatalogMakeRequest): Promise<CatalogMake> => {
|
||||
const response = await apiClient.put<CatalogMake>(`/admin/catalog/makes/${id}`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
deleteMake: async (id: string): Promise<void> => {
|
||||
await apiClient.delete(`/admin/catalog/makes/${id}`);
|
||||
},
|
||||
|
||||
// Catalog - Models
|
||||
listModels: async (makeId?: string): Promise<CatalogModel[]> => {
|
||||
const url = makeId ? `/admin/catalog/models?make_id=${makeId}` : '/admin/catalog/models';
|
||||
const response = await apiClient.get<CatalogModel[]>(url);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
createModel: async (data: CreateCatalogModelRequest): Promise<CatalogModel> => {
|
||||
const response = await apiClient.post<CatalogModel>('/admin/catalog/models', data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
updateModel: async (id: string, data: UpdateCatalogModelRequest): Promise<CatalogModel> => {
|
||||
const response = await apiClient.put<CatalogModel>(`/admin/catalog/models/${id}`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
deleteModel: async (id: string): Promise<void> => {
|
||||
await apiClient.delete(`/admin/catalog/models/${id}`);
|
||||
},
|
||||
|
||||
// Catalog - Years
|
||||
listYears: async (modelId?: string): Promise<CatalogYear[]> => {
|
||||
const url = modelId ? `/admin/catalog/years?model_id=${modelId}` : '/admin/catalog/years';
|
||||
const response = await apiClient.get<CatalogYear[]>(url);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
createYear: async (data: CreateCatalogYearRequest): Promise<CatalogYear> => {
|
||||
const response = await apiClient.post<CatalogYear>('/admin/catalog/years', data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
deleteYear: async (id: string): Promise<void> => {
|
||||
await apiClient.delete(`/admin/catalog/years/${id}`);
|
||||
},
|
||||
|
||||
// Catalog - Trims
|
||||
listTrims: async (yearId?: string): Promise<CatalogTrim[]> => {
|
||||
const url = yearId ? `/admin/catalog/trims?year_id=${yearId}` : '/admin/catalog/trims';
|
||||
const response = await apiClient.get<CatalogTrim[]>(url);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
createTrim: async (data: CreateCatalogTrimRequest): Promise<CatalogTrim> => {
|
||||
const response = await apiClient.post<CatalogTrim>('/admin/catalog/trims', data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
updateTrim: async (id: string, data: UpdateCatalogTrimRequest): Promise<CatalogTrim> => {
|
||||
const response = await apiClient.put<CatalogTrim>(`/admin/catalog/trims/${id}`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
deleteTrim: async (id: string): Promise<void> => {
|
||||
await apiClient.delete(`/admin/catalog/trims/${id}`);
|
||||
},
|
||||
|
||||
// Catalog - Engines
|
||||
listEngines: async (trimId?: string): Promise<CatalogEngine[]> => {
|
||||
const url = trimId ? `/admin/catalog/engines?trim_id=${trimId}` : '/admin/catalog/engines';
|
||||
const response = await apiClient.get<CatalogEngine[]>(url);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
createEngine: async (data: CreateCatalogEngineRequest): Promise<CatalogEngine> => {
|
||||
const response = await apiClient.post<CatalogEngine>('/admin/catalog/engines', data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
updateEngine: async (id: string, data: UpdateCatalogEngineRequest): Promise<CatalogEngine> => {
|
||||
const response = await apiClient.put<CatalogEngine>(`/admin/catalog/engines/${id}`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
deleteEngine: async (id: string): Promise<void> => {
|
||||
await apiClient.delete(`/admin/catalog/engines/${id}`);
|
||||
},
|
||||
|
||||
// Stations
|
||||
listStations: async (): Promise<StationOverview[]> => {
|
||||
const response = await apiClient.get<StationOverview[]>('/admin/stations');
|
||||
return response.data;
|
||||
},
|
||||
|
||||
createStation: async (data: CreateStationRequest): Promise<StationOverview> => {
|
||||
const response = await apiClient.post<StationOverview>('/admin/stations', data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
updateStation: async (id: string, data: UpdateStationRequest): Promise<StationOverview> => {
|
||||
const response = await apiClient.put<StationOverview>(`/admin/stations/${id}`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
deleteStation: async (id: string): Promise<void> => {
|
||||
await apiClient.delete(`/admin/stations/${id}`);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user