Files
gridpilot.gg/apps/website/lib/services/drivers/DriverService.ts

63 lines
2.1 KiB
TypeScript

import { DriversApiClient } from "@/lib/api/drivers/DriversApiClient";
import { CompleteOnboardingInputDTO } from "@/lib/types/generated/CompleteOnboardingInputDTO";
import { DriverProfileDTO } from "@/lib/types/generated/DriverProfileDTO";
import { CompleteOnboardingViewModel } from "@/lib/view-models/CompleteOnboardingViewModel";
import { DriverLeaderboardViewModel } from "@/lib/view-models/DriverLeaderboardViewModel";
import { DriverViewModel } from "@/lib/view-models/DriverViewModel";
import { DriverProfileViewModel } from "@/lib/view-models/DriverProfileViewModel";
// TODO: Create proper DriverDTO in generated types
type DriverDTO = {
id: string;
name: string;
avatarUrl?: string;
iracingId?: string;
rating?: number;
};
/**
* Driver Service
*
* Orchestrates driver operations by coordinating API calls and view model creation.
* All dependencies are injected via constructor.
*/
export class DriverService {
constructor(
private readonly apiClient: DriversApiClient
) {}
/**
* Get driver leaderboard with view model transformation
*/
async getDriverLeaderboard(): Promise<DriverLeaderboardViewModel> {
const dto = await this.apiClient.getLeaderboard();
return new DriverLeaderboardViewModel(dto);
}
/**
* Complete driver onboarding with view model transformation
*/
async completeDriverOnboarding(input: CompleteOnboardingInputDTO): Promise<CompleteOnboardingViewModel> {
const dto = await this.apiClient.completeOnboarding(input);
return new CompleteOnboardingViewModel(dto);
}
/**
* Get current driver with view model transformation
*/
async getCurrentDriver(): Promise<DriverViewModel | null> {
const dto = await this.apiClient.getCurrent();
if (!dto) {
return null;
}
return new DriverViewModel(dto);
}
/**
* Get driver profile with full details and view model transformation
*/
async getDriverProfile(driverId: string): Promise<DriverProfileViewModel> {
const dto = await this.apiClient.getDriverProfile(driverId);
return new DriverProfileViewModel(dto);
}
}