refactor use cases

This commit is contained in:
2026-01-08 15:34:51 +01:00
parent d984ab24a8
commit 52e9a2f6a7
362 changed files with 5192 additions and 8409 deletions

View File

@@ -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 {
});
}
}
}
}