82 lines
2.7 KiB
TypeScript
82 lines
2.7 KiB
TypeScript
import { Game } from '@core/racing/domain/entities/Game';
|
|
import { Season } from '@core/racing/domain/entities/season/Season';
|
|
import type { LeagueScoringConfig } from '@core/racing/domain/entities/LeagueScoringConfig';
|
|
import { InMemoryGameRepository } from '../racing/persistence/inmemory/InMemoryScoringRepositories';
|
|
import { InMemorySeasonRepository } from '../racing/persistence/inmemory/InMemoryScoringRepositories';
|
|
import { InMemoryLeagueScoringConfigRepository } from '../racing/persistence/inmemory/InMemoryScoringRepositories';
|
|
import { InMemoryChampionshipStandingRepository } from '../racing/persistence/inmemory/InMemoryScoringRepositories';
|
|
import type { Logger } from '@core/shared/application';
|
|
import { getLeagueScoringPresetById } from './LeagueScoringPresets';
|
|
|
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
class SilentLogger implements Logger {
|
|
debug(..._args: unknown[]): void {
|
|
// console.debug(...args);
|
|
}
|
|
info(..._args: unknown[]): void {
|
|
// console.info(...args);
|
|
}
|
|
warn(..._args: unknown[]): void {
|
|
// console.warn(...args);
|
|
}
|
|
error(..._args: unknown[]): void {
|
|
// console.error(...args);
|
|
}
|
|
}
|
|
|
|
export function createSprintMainDemoScoringSetup(params: {
|
|
leagueId: string;
|
|
seasonId?: string;
|
|
}): {
|
|
gameRepo: InMemoryGameRepository;
|
|
seasonRepo: InMemorySeasonRepository;
|
|
scoringConfigRepo: InMemoryLeagueScoringConfigRepository;
|
|
championshipStandingRepo: InMemoryChampionshipStandingRepository;
|
|
seasonId: string;
|
|
championshipId: string;
|
|
} {
|
|
const { leagueId } = params;
|
|
const seasonId = params.seasonId ?? 'season-sprint-main-demo';
|
|
const championshipId = 'driver-champ';
|
|
|
|
const logger = new SilentLogger();
|
|
|
|
const game = Game.create({ id: 'iracing', name: 'iRacing' });
|
|
|
|
const season = Season.create({
|
|
id: seasonId,
|
|
leagueId,
|
|
gameId: game.id.toString(),
|
|
name: 'Sprint + Main Demo Season',
|
|
year: 2025,
|
|
order: 1,
|
|
status: 'active',
|
|
startDate: new Date('2025-01-01'),
|
|
endDate: new Date('2025-12-31'),
|
|
});
|
|
|
|
const preset = getLeagueScoringPresetById('sprint-main-driver');
|
|
if (!preset) {
|
|
throw new Error('Missing sprint-main-driver scoring preset');
|
|
}
|
|
|
|
const leagueScoringConfig: LeagueScoringConfig = preset.createConfig({
|
|
seasonId: season.id,
|
|
});
|
|
|
|
const gameRepo = new InMemoryGameRepository(logger, [game]);
|
|
const seasonRepo = new InMemorySeasonRepository(logger, [season]);
|
|
const scoringConfigRepo = new InMemoryLeagueScoringConfigRepository(logger, [
|
|
leagueScoringConfig,
|
|
]);
|
|
const championshipStandingRepo = new InMemoryChampionshipStandingRepository(logger);
|
|
|
|
return {
|
|
gameRepo,
|
|
seasonRepo,
|
|
scoringConfigRepo,
|
|
championshipStandingRepo,
|
|
seasonId: season.id,
|
|
championshipId,
|
|
};
|
|
} |