Files
gridpilot.gg/apps/website/lib/api/drivers/DriversApiClient.ts
2026-01-17 02:03:19 +01:00

54 lines
2.2 KiB
TypeScript

import { BaseApiClient } from '../base/BaseApiClient';
import type { CompleteOnboardingInputDTO } from '../../types/generated/CompleteOnboardingInputDTO';
import type { CompleteOnboardingOutputDTO } from '../../types/generated/CompleteOnboardingOutputDTO';
import type { DriverRegistrationStatusDTO } from '../../types/generated/DriverRegistrationStatusDTO';
import type { DriverLeaderboardItemDTO } from '../../types/generated/DriverLeaderboardItemDTO';
import type { GetDriverOutputDTO } from '../../types/generated/GetDriverOutputDTO';
import type { GetDriverProfileOutputDTO } from '../../types/generated/GetDriverProfileOutputDTO';
type DriversLeaderboardDto = {
drivers: DriverLeaderboardItemDTO[];
};
/**
* Drivers API Client
*
* Handles all driver-related API operations.
*/
export class DriversApiClient extends BaseApiClient {
/** Get drivers leaderboard */
getLeaderboard(): Promise<DriversLeaderboardDto> {
return this.get<DriversLeaderboardDto>('/drivers/leaderboard');
}
/** Complete driver onboarding */
completeOnboarding(input: CompleteOnboardingInputDTO): Promise<CompleteOnboardingOutputDTO> {
return this.post<CompleteOnboardingOutputDTO>('/drivers/complete-onboarding', input);
}
/** Get current driver (based on session) */
getCurrent(): Promise<GetDriverOutputDTO | null> {
return this.get<GetDriverOutputDTO | null>('/drivers/current', { allowUnauthenticated: true });
}
/** Get driver registration status for a specific race */
getRegistrationStatus(driverId: string, raceId: string): Promise<DriverRegistrationStatusDTO> {
return this.get<DriverRegistrationStatusDTO>(`/drivers/${driverId}/races/${raceId}/registration-status`);
}
/** Get driver by ID */
getDriver(driverId: string): Promise<GetDriverOutputDTO | null> {
return this.get<GetDriverOutputDTO | null>(`/drivers/${driverId}`);
}
/** Get driver profile with full details */
getDriverProfile(driverId: string): Promise<GetDriverProfileOutputDTO> {
return this.get<GetDriverProfileOutputDTO>(`/drivers/${driverId}/profile`);
}
/** Update current driver profile */
updateProfile(updates: { bio?: string; country?: string }): Promise<GetDriverOutputDTO> {
return this.put<GetDriverOutputDTO>('/drivers/profile', updates);
}
}