refactor to adapters

This commit is contained in:
2025-12-15 18:34:20 +01:00
parent fc671482c8
commit c817d76092
145 changed files with 906 additions and 361 deletions

View File

@@ -0,0 +1,49 @@
import type { SessionType } from '@gridpilot/racing/domain/types/SessionType';
import { PointsTable } from '@gridpilot/racing/domain/value-objects/PointsTable';
import type { BonusRule } from '@gridpilot/racing/domain/types/BonusRule';
import type { ChampionshipConfig } from '@gridpilot/racing/domain/types/ChampionshipConfig';
import { makePointsTable } from './PointsTableFactory';
export const makeChampionshipConfig = (params: {
id: string;
name: string;
sessionTypes: SessionType[];
mainPoints: number[];
sprintPoints?: number[];
mainBonusRules?: BonusRule[];
}): ChampionshipConfig => {
const { id, name, sessionTypes, mainPoints, sprintPoints, mainBonusRules } = params;
const pointsTableBySessionType: Record<SessionType, PointsTable> = {} as Record<SessionType, PointsTable>;
sessionTypes.forEach((sessionType) => {
if (sessionType === 'main') {
pointsTableBySessionType[sessionType] = makePointsTable(mainPoints);
} else if (sessionType === 'sprint' && sprintPoints) {
pointsTableBySessionType[sessionType] = makePointsTable(sprintPoints);
} else {
pointsTableBySessionType[sessionType] = new PointsTable({});
}
});
const bonusRulesBySessionType: Record<SessionType, BonusRule[]> = {} as Record<SessionType, BonusRule[]>;
sessionTypes.forEach((sessionType) => {
if (sessionType === 'main' && mainBonusRules) {
bonusRulesBySessionType[sessionType] = mainBonusRules;
} else {
bonusRulesBySessionType[sessionType] = [];
}
});
return {
id,
name,
type: 'driver',
sessionTypes,
pointsTableBySessionType,
bonusRulesBySessionType,
dropScorePolicy: {
strategy: 'none',
},
};
};

View File

@@ -0,0 +1,7 @@
import type { ParticipantRef } from '@gridpilot/racing/domain/types/ParticipantRef';
import type { ChampionshipType } from '@gridpilot/racing/domain/types/ChampionshipType';
export const makeDriverRef = (id: string): ParticipantRef => ({
type: 'driver' as ChampionshipType,
id,
});

View File

@@ -0,0 +1,9 @@
import { PointsTable } from '@gridpilot/racing/domain/value-objects/PointsTable';
export const makePointsTable = (points: number[]): PointsTable => {
const pointsByPosition: Record<number, number> = {};
points.forEach((value, index) => {
pointsByPosition[index + 1] = value;
});
return new PointsTable(pointsByPosition);
};

View File

@@ -0,0 +1,23 @@
import { Season } from '@gridpilot/racing/domain/entities/Season';
import type { SeasonStatus } from '@gridpilot/racing/domain/entities/Season';
export const createMinimalSeason = (overrides?: { status?: SeasonStatus }) =>
Season.create({
id: 'season-1',
leagueId: 'league-1',
gameId: 'iracing',
name: 'Test Season',
status: overrides?.status ?? 'planned',
});
export const createBaseSeason = () =>
Season.create({
id: 'season-1',
leagueId: 'league-1',
gameId: 'iracing',
name: 'Config Season',
status: 'planned',
startDate: new Date('2025-01-01T00:00:00Z'),
endDate: undefined,
maxDrivers: 24,
});