refactor use cases
This commit is contained in:
@@ -4,7 +4,6 @@ import type { IDriverRepository } from '../../domain/repositories/IDriverReposit
|
||||
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { Race } from '../../domain/entities/Race';
|
||||
import type { Protest } from '../../domain/entities/Protest';
|
||||
import type { Driver } from '../../domain/entities/Driver';
|
||||
@@ -34,16 +33,11 @@ export class GetLeagueProtestsUseCase {
|
||||
private readonly protestRepository: IProtestRepository,
|
||||
private readonly driverRepository: IDriverRepository,
|
||||
private readonly leagueRepository: ILeagueRepository,
|
||||
private readonly output: UseCaseOutputPort<GetLeagueProtestsResult>,
|
||||
) {}
|
||||
|
||||
get outputPort(): UseCaseOutputPort<GetLeagueProtestsResult> {
|
||||
return this.output;
|
||||
}
|
||||
|
||||
async execute(
|
||||
input: GetLeagueProtestsInput,
|
||||
): Promise<Result<void, ApplicationErrorCode<GetLeagueProtestsErrorCode, { message: string }>>> {
|
||||
): Promise<Result<GetLeagueProtestsResult, ApplicationErrorCode<GetLeagueProtestsErrorCode, { message: string }>>> {
|
||||
try {
|
||||
const league = await this.leagueRepository.findById(input.leagueId);
|
||||
|
||||
@@ -89,9 +83,7 @@ export class GetLeagueProtestsUseCase {
|
||||
protests: protestsWithEntities,
|
||||
};
|
||||
|
||||
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