refactor driver module (wip)
This commit is contained in:
@@ -1,18 +1,20 @@
|
||||
import type {
|
||||
CompleteDriverOnboardingResult,
|
||||
} from '@core/racing/application/use-cases/CompleteDriverOnboardingUseCase';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { CompleteOnboardingOutputDTO } from '../dtos/CompleteOnboardingOutputDTO';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
|
||||
export class CompleteOnboardingPresenter
|
||||
implements UseCaseOutputPort<CompleteDriverOnboardingResult>
|
||||
{
|
||||
export class CompleteOnboardingPresenter {
|
||||
private responseModel: CompleteOnboardingOutputDTO | null = null;
|
||||
|
||||
present(result: CompleteDriverOnboardingResult): void {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
present(result: Result<any, any>): void {
|
||||
if (result.isErr()) {
|
||||
const error = result.unwrapErr();
|
||||
throw new Error(error.details?.message ?? 'Failed to complete onboarding');
|
||||
}
|
||||
|
||||
const data = result.unwrap();
|
||||
this.responseModel = {
|
||||
success: true,
|
||||
driverId: result.driver.id,
|
||||
driverId: data.driver.id,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { Driver } from '@core/racing/domain/entities/Driver';
|
||||
import type { GetDriverOutputDTO } from '../dtos/GetDriverOutputDTO';
|
||||
|
||||
export class DriverPresenter {
|
||||
private responseModel: GetDriverOutputDTO | null = null;
|
||||
|
||||
present(driver: Driver | null): void {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
present(result: Result<Driver | null, any>): void {
|
||||
if (result.isErr()) {
|
||||
const error = result.unwrapErr();
|
||||
throw new Error(error.details?.message ?? 'Failed to get driver');
|
||||
}
|
||||
|
||||
const driver = result.unwrap();
|
||||
if (!driver) {
|
||||
this.responseModel = null;
|
||||
return;
|
||||
@@ -15,8 +23,8 @@ export class DriverPresenter {
|
||||
iracingId: driver.iracingId.toString(),
|
||||
name: driver.name.toString(),
|
||||
country: driver.country.toString(),
|
||||
bio: driver.bio?.toString(),
|
||||
joinedAt: driver.joinedAt.toDate().toISOString(),
|
||||
...(driver.bio ? { bio: driver.bio.toString() } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import type {
|
||||
GetProfileOverviewResult,
|
||||
} from '@core/racing/application/use-cases/GetProfileOverviewUseCase';
|
||||
import type { GetDriverProfileOutputDTO } from '../dtos/GetDriverProfileOutputDTO';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { GetDriverProfileOutputDTO, DriverProfileExtendedProfileDTO } from '../dtos/GetDriverProfileOutputDTO';
|
||||
|
||||
export class DriverProfilePresenter
|
||||
implements UseCaseOutputPort<GetProfileOverviewResult>
|
||||
{
|
||||
private responseModel: GetDriverProfileOutputDTO | null = null;
|
||||
|
||||
@@ -45,7 +43,7 @@ export class DriverProfilePresenter
|
||||
avatarUrl: '', // TODO: get avatar
|
||||
})),
|
||||
},
|
||||
extendedProfile: result.extendedProfile as any,
|
||||
extendedProfile: result.extendedProfile as DriverProfileExtendedProfileDTO | null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -54,7 +52,7 @@ export class DriverProfilePresenter
|
||||
return this.responseModel;
|
||||
}
|
||||
|
||||
private getAvatarUrl(driverId: string): string | undefined {
|
||||
private getAvatarUrl(_driverId: string): string | undefined {
|
||||
// Avatar resolution is delegated to infrastructure; keep as-is for now.
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -2,11 +2,8 @@ import type {
|
||||
IsDriverRegisteredForRaceResult,
|
||||
} from '@core/racing/application/use-cases/IsDriverRegisteredForRaceUseCase';
|
||||
import { DriverRegistrationStatusDTO } from '../dtos/DriverRegistrationStatusDTO';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
|
||||
export class DriverRegistrationStatusPresenter
|
||||
implements UseCaseOutputPort<IsDriverRegisteredForRaceResult>
|
||||
{
|
||||
export class DriverRegistrationStatusPresenter {
|
||||
private responseModel: DriverRegistrationStatusDTO | null = null;
|
||||
|
||||
reset(): void {
|
||||
|
||||
@@ -2,11 +2,8 @@ import { DriverStatsDTO } from '../dtos/DriverStatsDTO';
|
||||
import type {
|
||||
GetTotalDriversResult,
|
||||
} from '@core/racing/application/use-cases/GetTotalDriversUseCase';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
|
||||
export class DriverStatsPresenter
|
||||
implements UseCaseOutputPort<GetTotalDriversResult>
|
||||
{
|
||||
export class DriverStatsPresenter {
|
||||
private responseModel: DriverStatsDTO | null = null;
|
||||
|
||||
present(result: GetTotalDriversResult): void {
|
||||
|
||||
@@ -19,11 +19,11 @@ describe('DriversLeaderboardPresenter', () => {
|
||||
{
|
||||
driver: {
|
||||
id: 'driver-1',
|
||||
name: 'Driver One' as any,
|
||||
country: 'US' as any,
|
||||
} as any,
|
||||
name: 'Driver One' as unknown,
|
||||
country: 'US' as unknown,
|
||||
} as unknown,
|
||||
rating: 2500,
|
||||
skillLevel: 'advanced' as any,
|
||||
skillLevel: 'advanced' as unknown,
|
||||
racesCompleted: 50,
|
||||
wins: 10,
|
||||
podiums: 20,
|
||||
@@ -34,11 +34,11 @@ describe('DriversLeaderboardPresenter', () => {
|
||||
{
|
||||
driver: {
|
||||
id: 'driver-2',
|
||||
name: 'Driver Two' as any,
|
||||
country: 'DE' as any,
|
||||
} as any,
|
||||
name: 'Driver Two' as unknown,
|
||||
country: 'DE' as unknown,
|
||||
} as unknown,
|
||||
rating: 2400,
|
||||
skillLevel: 'intermediate' as any,
|
||||
skillLevel: 'intermediate' as unknown,
|
||||
racesCompleted: 40,
|
||||
wins: 5,
|
||||
podiums: 15,
|
||||
|
||||
@@ -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