fix issues in core

This commit is contained in:
2025-12-23 11:25:08 +01:00
parent 1efd971032
commit 2854ae3c5c
113 changed files with 1142 additions and 458 deletions

View File

@@ -52,16 +52,25 @@ export class CompleteRaceUseCaseWithRatings {
const race = await this.raceRepository.findById(raceId);
if (!race) {
return Result.err({ code: 'RACE_NOT_FOUND' });
return Result.err({
code: 'RACE_NOT_FOUND',
details: { message: 'Race not found' }
});
}
if (race.status === 'completed') {
return Result.err({ code: 'ALREADY_COMPLETED' });
return Result.err({
code: 'ALREADY_COMPLETED',
details: { message: 'Race already completed' }
});
}
const registeredDriverIds = await this.raceRegistrationRepository.getRegisteredDrivers(raceId);
if (registeredDriverIds.length === 0) {
return Result.err({ code: 'NO_REGISTERED_DRIVERS' });
return Result.err({
code: 'NO_REGISTERED_DRIVERS',
details: { message: 'No registered drivers' }
});
}
const driverRatings = this.driverRatingProvider.getRatings(registeredDriverIds);
@@ -107,23 +116,24 @@ export class CompleteRaceUseCaseWithRatings {
private async updateStandings(leagueId: string, results: RaceResult[]): Promise<void> {
const resultsByDriver = new Map<string, RaceResult[]>();
for (const result of results) {
const existing = resultsByDriver.get(result.driverId) || [];
const driverIdStr = result.driverId.toString();
const existing = resultsByDriver.get(driverIdStr) || [];
existing.push(result);
resultsByDriver.set(result.driverId, existing);
resultsByDriver.set(driverIdStr, existing);
}
for (const [driverId, driverResults] of resultsByDriver) {
let standing = await this.standingRepository.findByDriverIdAndLeagueId(driverId, leagueId);
for (const [driverIdStr, driverResults] of resultsByDriver) {
let standing = await this.standingRepository.findByDriverIdAndLeagueId(driverIdStr, leagueId);
if (!standing) {
standing = Standing.create({
leagueId,
driverId,
driverId: driverIdStr,
});
}
for (const result of driverResults) {
standing = standing.addRaceResult(result.position, {
standing = standing.addRaceResult(result.position.toNumber(), {
1: 25,
2: 18,
3: 15,
@@ -143,11 +153,11 @@ export class CompleteRaceUseCaseWithRatings {
private async updateDriverRatings(results: RaceResult[], totalDrivers: number): Promise<void> {
const driverResults = results.map((result) => ({
driverId: result.driverId,
position: result.position,
driverId: result.driverId.toString(),
position: result.position.toNumber(),
totalDrivers,
incidents: result.incidents,
startPosition: result.startPosition,
incidents: result.incidents.toNumber(),
startPosition: result.startPosition.toNumber(),
}));
await this.ratingUpdateService.updateDriverRatingsAfterRace(driverResults);