api client refactor

This commit is contained in:
2025-12-17 19:25:10 +01:00
parent 4177644b18
commit 26f7a2b6aa
27 changed files with 543 additions and 1329 deletions

View File

@@ -2,15 +2,42 @@ import { api as api } from '../../api';
import { presentDriversLeaderboard } from '../../presenters';
import { DriverLeaderboardViewModel } from '../../view-models';
/**
* Driver Service
*
* Handles driver-related operations including profiles, leaderboards, and onboarding.
*/
export class DriverService {
constructor(
private readonly apiClient = api.drivers
) {}
async getDriverLeaderboard(): Promise<DriverLeaderboardViewModel> {
const dto = await this.apiClient.getLeaderboard();
return presentDriversLeaderboard(dto);
}
async completeDriverOnboarding(input: any): Promise<any> {
return await this.apiClient.completeOnboarding(input);
}
async getCurrentDriver(): Promise<any> {
return await this.apiClient.getCurrent();
}
}
// Singleton instance
export const driverService = new DriverService();
// Backward compatibility functional exports
export async function getDriverLeaderboard(): Promise<DriverLeaderboardViewModel> {
const dto = await api.drivers.getLeaderboard();
return presentDriversLeaderboard(dto);
return driverService.getDriverLeaderboard();
}
export async function completeDriverOnboarding(input: any): Promise<any> {
return await api.drivers.completeOnboarding(input);
return driverService.completeDriverOnboarding(input);
}
export async function getCurrentDriver(): Promise<any> {
return await api.drivers.getCurrent();
return driverService.getCurrentDriver();
}

View File

@@ -0,0 +1,6 @@
// Export the class-based service
export { DriverService, driverService } from './DriverService';
// Export backward compatibility functions
export { getDriverLeaderboard, completeDriverOnboarding, getCurrentDriver } from './DriverService';
export { registerDriver, getDriverRegistrationStatus } from './DriverRegistrationService';