refactor use cases
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { ILeagueMembershipRepository } from '../../domain/repositories/ILeagueMembershipRepository';
|
||||
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
||||
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
|
||||
import type { LeagueMembership } from '../../domain/entities/LeagueMembership';
|
||||
import type { Driver } from '../../domain/entities/Driver';
|
||||
import type { League } from '../../domain/entities/League';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
export interface GetLeagueMembershipsInput {
|
||||
leagueId: string;
|
||||
@@ -29,12 +28,11 @@ export class GetLeagueMembershipsUseCase {
|
||||
private readonly leagueMembershipRepository: ILeagueMembershipRepository,
|
||||
private readonly driverRepository: IDriverRepository,
|
||||
private readonly leagueRepository: ILeagueRepository,
|
||||
private readonly output: UseCaseOutputPort<GetLeagueMembershipsResult>,
|
||||
) {}
|
||||
|
||||
async execute(
|
||||
input: GetLeagueMembershipsInput,
|
||||
): Promise<Result<void, ApplicationErrorCode<GetLeagueMembershipsErrorCode, { message: string }>>> {
|
||||
): Promise<Result<GetLeagueMembershipsResult, ApplicationErrorCode<GetLeagueMembershipsErrorCode, { message: string }>>> {
|
||||
try {
|
||||
const league = await this.leagueRepository.findById(input.leagueId);
|
||||
|
||||
@@ -63,9 +61,7 @@ export class GetLeagueMembershipsUseCase {
|
||||
memberships: membershipsWithDrivers,
|
||||
};
|
||||
|
||||
this.output.present(result);
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok(result);
|
||||
} catch (error: unknown) {
|
||||
const message = error instanceof Error ? error.message : 'Failed to load league memberships';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user