refactor use cases
This commit is contained in:
@@ -11,7 +11,6 @@ import type { Protest } from '../../domain/entities/Protest';
|
||||
import type { Driver } from '../../domain/entities/Driver';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
|
||||
export interface GetRaceProtestsInput {
|
||||
raceId: string;
|
||||
@@ -28,12 +27,11 @@ export class GetRaceProtestsUseCase {
|
||||
constructor(
|
||||
private readonly protestRepository: IProtestRepository,
|
||||
private readonly driverRepository: IDriverRepository,
|
||||
private readonly output: UseCaseOutputPort<GetRaceProtestsResult>,
|
||||
) {}
|
||||
|
||||
async execute(
|
||||
input: GetRaceProtestsInput,
|
||||
): Promise<Result<void, ApplicationErrorCode<GetRaceProtestsErrorCode, { message: string }>>> {
|
||||
): Promise<Result<GetRaceProtestsResult, ApplicationErrorCode<GetRaceProtestsErrorCode, { message: string }>>> {
|
||||
try {
|
||||
const protests = await this.protestRepository.findByRaceId(input.raceId);
|
||||
|
||||
@@ -57,9 +55,7 @@ export class GetRaceProtestsUseCase {
|
||||
drivers: validDrivers,
|
||||
};
|
||||
|
||||
this.output.present(result);
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok(result);
|
||||
} catch (error: unknown) {
|
||||
const message =
|
||||
error instanceof Error && error.message
|
||||
|
||||
Reference in New Issue
Block a user