refactor use cases
This commit is contained in:
@@ -2,7 +2,6 @@ import type { ILeagueMembershipRepository } from '../../domain/repositories/ILea
|
||||
import type { IRaceRepository } from '../../domain/repositories/IRaceRepository';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
|
||||
export interface GetLeagueStatsInput {
|
||||
leagueId: string;
|
||||
@@ -24,12 +23,11 @@ export class GetLeagueStatsUseCase {
|
||||
private readonly getDriverRating: (input: {
|
||||
driverId: string;
|
||||
}) => Promise<{ rating: number | null; ratingChange: number | null }>,
|
||||
private readonly output: UseCaseOutputPort<GetLeagueStatsResult>,
|
||||
) {}
|
||||
|
||||
async execute(
|
||||
input: GetLeagueStatsInput,
|
||||
): Promise<Result<void, ApplicationErrorCode<GetLeagueStatsErrorCode, { message: string }>>> {
|
||||
): Promise<Result<GetLeagueStatsResult, ApplicationErrorCode<GetLeagueStatsErrorCode, { message: string }>>> {
|
||||
try {
|
||||
const memberships = await this.leagueMembershipRepository.getLeagueMembers(input.leagueId);
|
||||
|
||||
@@ -62,9 +60,7 @@ export class GetLeagueStatsUseCase {
|
||||
averageRating,
|
||||
};
|
||||
|
||||
this.output.present(result);
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
const message =
|
||||
error instanceof Error && error.message ? error.message : 'Failed to fetch league stats';
|
||||
@@ -75,4 +71,4 @@ export class GetLeagueStatsUseCase {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user