This commit is contained in:
2025-12-21 22:35:38 +01:00
parent 3c64f328e2
commit 9bd2e630e6
38 changed files with 736 additions and 684 deletions

View File

@@ -96,11 +96,14 @@ export class RaceService {
async getAllRaces(): Promise<GetAllRacesPresenter> {
this.logger.debug('[RaceService] Fetching all races.');
const presenter = new GetAllRacesPresenter();
this.getAllRacesUseCase.setOutput(presenter);
const result = await this.getAllRacesUseCase.execute({});
const presenter = new GetAllRacesPresenter();
presenter.reset();
presenter.present(result);
if (result.isErr()) {
throw new Error(result.unwrapErr().code);
}
return presenter;
}

View File

@@ -1,37 +1,17 @@
import type { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type {
GetAllRacesResult,
GetAllRacesErrorCode,
} from '@core/racing/application/use-cases/GetAllRacesUseCase';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
import type { GetAllRacesResult } from '@core/racing/application/use-cases/GetAllRacesUseCase';
import type { AllRacesPageDTO } from '../dtos/AllRacesPageDTO';
export type GetAllRacesResponseModel = AllRacesPageDTO;
export type GetAllRacesApplicationError = ApplicationErrorCode<
GetAllRacesErrorCode,
{ message: string }
>;
export class GetAllRacesPresenter {
export class GetAllRacesPresenter implements UseCaseOutputPort<GetAllRacesResult> {
private model: GetAllRacesResponseModel | null = null;
reset(): void {
this.model = null;
}
present(result: Result<GetAllRacesResult, GetAllRacesApplicationError>): void {
if (result.isErr()) {
const error = result.unwrapErr();
throw new Error(error.details?.message ?? 'Failed to get all races');
}
const output = result.unwrap();
present(result: GetAllRacesResult): void {
const leagueMap = new Map<string, string>();
const uniqueLeagues = new Map<string, { id: string; name: string }>();
for (const league of output.leagues) {
for (const league of result.leagues) {
const id = league.id.toString();
const name = league.name.toString();
leagueMap.set(id, name);
@@ -39,7 +19,7 @@ export class GetAllRacesPresenter {
}
this.model = {
races: output.races.map(race => ({
races: result.races.map(race => ({
id: race.id,
track: race.track,
car: race.car,