refactor
This commit is contained in:
@@ -7,27 +7,22 @@
|
||||
|
||||
import type { IPenaltyRepository } from '../../domain/repositories/IPenaltyRepository';
|
||||
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
||||
import type {
|
||||
IRacePenaltiesPresenter,
|
||||
RacePenaltiesResultDTO,
|
||||
RacePenaltiesViewModel,
|
||||
} from '../presenters/IRacePenaltiesPresenter';
|
||||
import type { UseCase } from '@core/shared/application/UseCase';
|
||||
import type { RacePenaltiesResultDTO } from '../presenters/IRacePenaltiesPresenter';
|
||||
import type { AsyncUseCase } from '@core/shared/application/AsyncUseCase';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
export interface GetRacePenaltiesInput {
|
||||
raceId: string;
|
||||
}
|
||||
|
||||
export class GetRacePenaltiesUseCase
|
||||
implements
|
||||
UseCase<GetRacePenaltiesInput, RacePenaltiesResultDTO, RacePenaltiesViewModel, IRacePenaltiesPresenter>
|
||||
{
|
||||
export class GetRacePenaltiesUseCase implements AsyncUseCase<GetRacePenaltiesInput, RacePenaltiesResultDTO, 'NO_ERROR'> {
|
||||
constructor(
|
||||
private readonly penaltyRepository: IPenaltyRepository,
|
||||
private readonly driverRepository: IDriverRepository,
|
||||
) {}
|
||||
|
||||
async execute(input: GetRacePenaltiesInput, presenter: IRacePenaltiesPresenter): Promise<void> {
|
||||
async execute(input: GetRacePenaltiesInput): Promise<Result<RacePenaltiesResultDTO, ApplicationErrorCode<'NO_ERROR'>>> {
|
||||
const penalties = await this.penaltyRepository.findByRaceId(input.raceId);
|
||||
|
||||
const driverIds = new Set<string>();
|
||||
@@ -47,11 +42,10 @@ export class GetRacePenaltiesUseCase
|
||||
}
|
||||
});
|
||||
|
||||
presenter.reset();
|
||||
const dto: RacePenaltiesResultDTO = {
|
||||
penalties,
|
||||
driverMap,
|
||||
};
|
||||
presenter.present(dto);
|
||||
return Result.ok(dto);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user