Files
Marc Mintel 597bb48248
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 4m51s
Contract Testing / contract-snapshot (pull_request) Has been skipped
integration tests
2026-01-22 17:29:06 +01:00

51 lines
1.5 KiB
TypeScript

/**
* Application Use Case Interface: RankingUseCase
*
* Use case for computing driver rankings from standings and results.
* This is an application layer concern that orchestrates domain data.
*/
import type { StandingRepository } from '../../domain/repositories/StandingRepository';
import type { DriverRepository } from '../../domain/repositories/DriverRepository';
import type { DriverStatsRepository } from '../../domain/repositories/DriverStatsRepository';
import type { Logger } from '@core/shared/domain/Logger';
export interface DriverRanking {
driverId: string;
rating: number;
wins: number;
totalRaces: number;
overallRank: number | null;
}
export class RankingUseCase {
constructor(
_standingRepository: StandingRepository,
_driverRepository: DriverRepository,
private readonly _driverStatsRepository: DriverStatsRepository,
private readonly _logger: Logger,
) {}
async getAllDriverRankings(): Promise<DriverRanking[]> {
this._logger.debug('Getting all driver rankings');
const allStats = await this._driverStatsRepository.getAllStats();
const rankings: DriverRanking[] = [];
allStats.forEach((stats, driverId) => {
rankings.push({
driverId,
rating: stats.rating,
wins: stats.wins,
totalRaces: stats.totalRaces,
overallRank: stats.overallRank,
});
});
return rankings;
}
clear(): void {
this._logger.info('[RankingUseCase] Clearing all rankings');
// No data to clear as this use case generates data on-the-fly
}
}