refactor api modules
This commit is contained in:
@@ -7,19 +7,19 @@ export interface CommandResultDTO {
|
||||
message?: string;
|
||||
}
|
||||
|
||||
export type CommandApplicationError<E extends string = string> = ApplicationErrorCode<
|
||||
E,
|
||||
export type CommandApplicationError = ApplicationErrorCode<
|
||||
string,
|
||||
{ message: string }
|
||||
>;
|
||||
|
||||
export class CommandResultPresenter<E extends string = string> {
|
||||
export class CommandResultPresenter {
|
||||
private model: CommandResultDTO | null = null;
|
||||
|
||||
reset(): void {
|
||||
this.model = null;
|
||||
}
|
||||
|
||||
present(result: Result<unknown, CommandApplicationError<E>>): void {
|
||||
present(result: Result<unknown, CommandApplicationError>): void {
|
||||
if (result.isErr()) {
|
||||
const error = result.unwrapErr();
|
||||
this.model = {
|
||||
@@ -36,7 +36,7 @@ export class CommandResultPresenter<E extends string = string> {
|
||||
presentSuccess(message?: string): void {
|
||||
this.model = {
|
||||
success: true,
|
||||
message,
|
||||
...(message !== undefined && { message }),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ export class CommandResultPresenter<E extends string = string> {
|
||||
this.model = {
|
||||
success: false,
|
||||
errorCode,
|
||||
message,
|
||||
...(message !== undefined && { message }),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -59,4 +59,8 @@ export class CommandResultPresenter<E extends string = string> {
|
||||
|
||||
return this.model;
|
||||
}
|
||||
|
||||
get viewModel(): CommandResultDTO {
|
||||
return this.responseModel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,11 +40,11 @@ export class RaceDetailPresenter implements UseCaseOutputPort<GetRaceDetailResul
|
||||
track: output.race.track,
|
||||
car: output.race.car,
|
||||
scheduledAt: output.race.scheduledAt.toISOString(),
|
||||
sessionType: output.race.sessionType,
|
||||
status: output.race.status,
|
||||
sessionType: output.race.sessionType.toString(),
|
||||
status: output.race.status.toString(),
|
||||
strengthOfField: output.race.strengthOfField ?? null,
|
||||
registeredCount: output.race.registeredCount ?? undefined,
|
||||
maxParticipants: output.race.maxParticipants ?? undefined,
|
||||
...(output.race.registeredCount !== undefined && { registeredCount: output.race.registeredCount }),
|
||||
...(output.race.maxParticipants !== undefined && { maxParticipants: output.race.maxParticipants }),
|
||||
}
|
||||
: null;
|
||||
|
||||
@@ -54,22 +54,22 @@ export class RaceDetailPresenter implements UseCaseOutputPort<GetRaceDetailResul
|
||||
name: output.league.name.toString(),
|
||||
description: output.league.description.toString(),
|
||||
settings: {
|
||||
maxDrivers: output.league.settings.maxDrivers ?? undefined,
|
||||
qualifyingFormat: output.league.settings.qualifyingFormat ?? undefined,
|
||||
...(output.league.settings.maxDrivers !== undefined && { maxDrivers: output.league.settings.maxDrivers }),
|
||||
...(output.league.settings.qualifyingFormat !== undefined && { qualifyingFormat: output.league.settings.qualifyingFormat.toString() }),
|
||||
},
|
||||
}
|
||||
: null;
|
||||
|
||||
const entryListDTO: RaceDetailEntryDTO[] = await Promise.all(
|
||||
output.drivers.map(async driver => {
|
||||
const ratingResult = await this.driverRatingProvider.getDriverRating({ driverId: driver.id });
|
||||
const avatarResult = await this.imageService.getDriverAvatar({ driverId: driver.id });
|
||||
const rating = this.driverRatingProvider.getRating(driver.id);
|
||||
const avatarUrl = this.imageService.getDriverAvatar(driver.id);
|
||||
return {
|
||||
id: driver.id,
|
||||
name: driver.name.toString(),
|
||||
country: driver.country.toString(),
|
||||
avatarUrl: avatarResult.avatarUrl,
|
||||
rating: ratingResult.rating,
|
||||
avatarUrl,
|
||||
rating,
|
||||
isCurrentUser: driver.id === params.driverId,
|
||||
};
|
||||
}),
|
||||
|
||||
@@ -34,10 +34,10 @@ export class RaceProtestsPresenter {
|
||||
protestingDriverId: protest.protestingDriverId,
|
||||
accusedDriverId: protest.accusedDriverId,
|
||||
incident: {
|
||||
lap: protest.incident.lap,
|
||||
description: protest.incident.description,
|
||||
lap: protest.incident.lap.toNumber(),
|
||||
description: protest.incident.description.toString(),
|
||||
},
|
||||
status: protest.status,
|
||||
status: protest.status.toString(),
|
||||
filedAt: protest.filedAt.toISOString(),
|
||||
} as RaceProtestDTO));
|
||||
|
||||
|
||||
@@ -39,12 +39,12 @@ export class RaceResultsDetailPresenter {
|
||||
throw new Error(`Driver not found for result: ${singleResult.driverId}`);
|
||||
}
|
||||
|
||||
const avatarResult = await this.imageService.getDriverAvatar({ driverId: driver.id });
|
||||
const avatarUrl = this.imageService.getDriverAvatar(driver.id);
|
||||
|
||||
return {
|
||||
driverId: singleResult.driverId.toString(),
|
||||
driverName: driver.name.toString(),
|
||||
avatarUrl: avatarResult.avatarUrl,
|
||||
avatarUrl,
|
||||
position: singleResult.position.toNumber(),
|
||||
startPosition: singleResult.startPosition.toNumber(),
|
||||
incidents: singleResult.incidents.toNumber(),
|
||||
|
||||
Reference in New Issue
Block a user