43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
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> {
|
|
return driverService.getDriverLeaderboard();
|
|
}
|
|
|
|
export async function completeDriverOnboarding(input: any): Promise<any> {
|
|
return driverService.completeDriverOnboarding(input);
|
|
}
|
|
|
|
export async function getCurrentDriver(): Promise<any> {
|
|
return driverService.getCurrentDriver();
|
|
} |