refactor driver module (wip)
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
import { DriversLeaderboardDTO } from '../dtos/DriversLeaderboardDTO';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type {
|
||||
GetDriversLeaderboardResult,
|
||||
GetDriversLeaderboardErrorCode,
|
||||
} from '@core/racing/application/use-cases/GetDriversLeaderboardUseCase';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
|
||||
export class DriversLeaderboardPresenter implements UseCaseOutputPort<GetDriversLeaderboardResult> {
|
||||
export class DriversLeaderboardPresenter {
|
||||
private responseModel: DriversLeaderboardDTO | null = null;
|
||||
|
||||
present(result: GetDriversLeaderboardResult): void {
|
||||
present(result: Result<GetDriversLeaderboardResult, ApplicationErrorCode<GetDriversLeaderboardErrorCode, { message: string }>>): void {
|
||||
if (result.isErr()) {
|
||||
const error = result.unwrapErr();
|
||||
throw new Error(error.details?.message ?? 'Failed to get drivers leaderboard');
|
||||
}
|
||||
|
||||
const data = result.unwrap();
|
||||
this.responseModel = {
|
||||
drivers: result.items.map(item => ({
|
||||
drivers: data.items.map(item => ({
|
||||
id: item.driver.id,
|
||||
name: item.driver.name.toString(),
|
||||
rating: item.rating,
|
||||
@@ -20,11 +28,11 @@ export class DriversLeaderboardPresenter implements UseCaseOutputPort<GetDrivers
|
||||
podiums: item.podiums,
|
||||
isActive: item.isActive,
|
||||
rank: item.rank,
|
||||
avatarUrl: item.avatarUrl,
|
||||
...(item.avatarUrl !== undefined ? { avatarUrl: item.avatarUrl } : {}),
|
||||
})),
|
||||
totalRaces: result.totalRaces,
|
||||
totalWins: result.totalWins,
|
||||
activeCount: result.activeCount,
|
||||
totalRaces: data.totalRaces,
|
||||
totalWins: data.totalWins,
|
||||
activeCount: data.activeCount,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user