refactor use cases

This commit is contained in:
2026-01-08 15:34:51 +01:00
parent d984ab24a8
commit 52e9a2f6a7
362 changed files with 5192 additions and 8409 deletions

View File

@@ -9,7 +9,6 @@ import type { IPenaltyRepository } from '../../domain/repositories/IPenaltyRepos
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { UseCaseOutputPort } from '@core/shared/application';
import type { Driver } from '../../domain/entities/Driver';
import type { Penalty } from '../../domain/entities/penalty/Penalty';
@@ -28,12 +27,11 @@ export class GetRacePenaltiesUseCase {
constructor(
private readonly penaltyRepository: IPenaltyRepository,
private readonly driverRepository: IDriverRepository,
private readonly output: UseCaseOutputPort<GetRacePenaltiesResult>,
) {}
async execute(
input: GetRacePenaltiesInput,
): Promise<Result<void, ApplicationErrorCode<GetRacePenaltiesErrorCode, { message: string }>>> {
): Promise<Result<GetRacePenaltiesResult, ApplicationErrorCode<GetRacePenaltiesErrorCode, { message: string }>>> {
try {
const penalties = await this.penaltyRepository.findByRaceId(input.raceId);
@@ -49,9 +47,7 @@ export class GetRacePenaltiesUseCase {
const validDrivers = drivers.filter((driver): driver is NonNullable<typeof driver> => driver !== null);
this.output.present({ penalties, drivers: validDrivers });
return Result.ok(undefined);
return Result.ok({ penalties, drivers: validDrivers });
} catch (error: unknown) {
const message =
error instanceof Error && error.message