refactor use cases
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user