refactor core presenters
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
import type { IPenaltyRepository } from '../../domain/repositories/IPenaltyRepository';
|
||||
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
||||
import type { RacePenaltiesResultDTO } from '../presenters/IRacePenaltiesPresenter';
|
||||
import type { RacePenaltiesOutputPort } from '../ports/output/RacePenaltiesOutputPort';
|
||||
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 GetRacePenaltiesInput {
|
||||
raceId: string;
|
||||
}
|
||||
|
||||
export class GetRacePenaltiesUseCase implements AsyncUseCase<GetRacePenaltiesInput, RacePenaltiesResultDTO, 'NO_ERROR'> {
|
||||
export class GetRacePenaltiesUseCase implements AsyncUseCase<GetRacePenaltiesInput, RacePenaltiesOutputPort, 'NO_ERROR'> {
|
||||
constructor(
|
||||
private readonly penaltyRepository: IPenaltyRepository,
|
||||
private readonly driverRepository: IDriverRepository,
|
||||
) {}
|
||||
|
||||
async execute(input: GetRacePenaltiesInput): Promise<Result<RacePenaltiesResultDTO, ApplicationErrorCode<'NO_ERROR'>>> {
|
||||
async execute(input: GetRacePenaltiesInput): Promise<Result<RacePenaltiesOutputPort, ApplicationErrorCode<'NO_ERROR'>>> {
|
||||
const penalties = await this.penaltyRepository.findByRaceId(input.raceId);
|
||||
|
||||
const driverIds = new Set<string>();
|
||||
@@ -35,17 +35,12 @@ export class GetRacePenaltiesUseCase implements AsyncUseCase<GetRacePenaltiesInp
|
||||
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: RacePenaltiesResultDTO = {
|
||||
const outputPort: RacePenaltiesOutputPort = {
|
||||
penalties,
|
||||
driverMap,
|
||||
drivers: validDrivers,
|
||||
};
|
||||
return Result.ok(dto);
|
||||
return Result.ok(outputPort);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user