fix issues in core

This commit is contained in:
2025-12-23 14:43:49 +01:00
parent 11492d1ff2
commit df5c20c5cc
62 changed files with 480 additions and 334 deletions

View File

@@ -0,0 +1,58 @@
import type { ChampionshipConfig } from '../../../racing/domain/types/ChampionshipConfig';
import type { ChampionshipType } from '../../../racing/domain/types/ChampionshipType';
import type { SessionType } from '../../../racing/domain/types/SessionType';
import type { BonusRule } from '../../../racing/domain/types/BonusRule';
import type { DropScorePolicy, DropScoreStrategy } from '../../../racing/domain/types/DropScorePolicy';
import { PointsTable } from '../../../racing/domain/value-objects/PointsTable';
interface ChampionshipConfigInput {
id: string;
name: string;
sessionTypes: SessionType[];
mainPoints?: number[];
mainBonusRules?: BonusRule[];
type?: ChampionshipType;
dropScorePolicy?: DropScorePolicy;
strategy?: DropScoreStrategy;
}
export function makeChampionshipConfig(input: ChampionshipConfigInput): ChampionshipConfig {
const {
id,
name,
sessionTypes,
mainPoints = [25, 18, 15, 12, 10, 8, 6, 4, 2, 1],
mainBonusRules = [],
type = 'driver',
dropScorePolicy = { strategy: 'none' },
} = input;
const pointsTableBySessionType: Record<SessionType, PointsTable> = {} as Record<SessionType, PointsTable>;
// Convert array format to PointsTable for each session type
sessionTypes.forEach(sessionType => {
const pointsArray = mainPoints;
const pointsMap: Record<number, number> = {};
pointsArray.forEach((points, index) => {
pointsMap[index + 1] = points;
});
pointsTableBySessionType[sessionType] = new PointsTable(pointsMap);
});
const bonusRulesBySessionType: Record<SessionType, BonusRule[]> = {} as Record<SessionType, BonusRule[]>;
// Add bonus rules for each session type
sessionTypes.forEach(sessionType => {
bonusRulesBySessionType[sessionType] = mainBonusRules;
});
return {
id,
name,
type,
sessionTypes,
pointsTableBySessionType,
bonusRulesBySessionType,
dropScorePolicy,
};
}

View File

@@ -0,0 +1,9 @@
import type { DriverId } from '../../../racing/domain/entities/DriverId';
import type { ParticipantRef } from '../../../racing/domain/types/ParticipantRef';
export function makeDriverRef(driverId: string): ParticipantRef {
return {
id: driverId,
type: 'driver',
};
}

View File

@@ -0,0 +1,5 @@
import { PointsTable } from '../../../racing/domain/value-objects/PointsTable';
export function makePointsTable(points: number[]): PointsTable {
return new PointsTable(points);
}