api client refactor
This commit is contained in:
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user