refactor core presenters

This commit is contained in:
2025-12-19 19:42:19 +01:00
parent 8116fe888f
commit 94fc538f44
228 changed files with 2817 additions and 3097 deletions

View File

@@ -7,7 +7,7 @@
import type { IProtestRepository } from '../../domain/repositories/IProtestRepository';
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
import type { RaceProtestsResultDTO } from '../presenters/IRaceProtestsPresenter';
import type { RaceProtestsOutputPort } from '../ports/output/RaceProtestsOutputPort';
import type { AsyncUseCase } from '@core/shared/application/AsyncUseCase';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
@@ -16,13 +16,13 @@ export interface GetRaceProtestsInput {
raceId: string;
}
export class GetRaceProtestsUseCase implements AsyncUseCase<GetRaceProtestsInput, RaceProtestsResultDTO, 'NO_ERROR'> {
export class GetRaceProtestsUseCase implements AsyncUseCase<GetRaceProtestsInput, RaceProtestsOutputPort, 'NO_ERROR'> {
constructor(
private readonly protestRepository: IProtestRepository,
private readonly driverRepository: IDriverRepository,
) {}
async execute(input: GetRaceProtestsInput): Promise<Result<RaceProtestsResultDTO, ApplicationErrorCode<'NO_ERROR'>>> {
async execute(input: GetRaceProtestsInput): Promise<Result<RaceProtestsOutputPort, ApplicationErrorCode<'NO_ERROR'>>> {
const protests = await this.protestRepository.findByRaceId(input.raceId);
const driverIds = new Set<string>();
@@ -38,17 +38,12 @@ export class GetRaceProtestsUseCase implements AsyncUseCase<GetRaceProtestsInput
Array.from(driverIds).map((id) => this.driverRepository.findById(id)),
);
const driverMap = new Map<string, string>();
drivers.forEach((driver) => {
if (driver) {
driverMap.set(driver.id, driver.name);
}
});
const validDrivers = drivers.filter((driver): driver is NonNullable<typeof driver> => driver !== null);
const dto: RaceProtestsResultDTO = {
const outputPort: RaceProtestsOutputPort = {
protests,
driverMap,
drivers: validDrivers,
};
return Result.ok(dto);
return Result.ok(outputPort);
}
}