refactor core presenters
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user