Files
gridpilot.gg/adapters/bootstrap/racing/RacingLeagueFactory.ts
2025-12-27 01:53:36 +01:00

58 lines
2.1 KiB
TypeScript

import { League } from '@core/racing/domain/entities/League';
import { Driver } from '@core/racing/domain/entities/Driver';
import { faker } from '@faker-js/faker';
export class RacingLeagueFactory {
constructor(
private readonly baseDate: Date,
private readonly drivers: Driver[],
) {}
create(): League[] {
const leagueCount = 20;
const pointsSystems = ['f1-2024', 'indycar', 'custom'] as const;
const qualifyingFormats = ['open', 'single-lap'] as const;
return Array.from({ length: leagueCount }, (_, idx) => {
const i = idx + 1;
const owner = faker.helpers.arrayElement(this.drivers);
const socialLinks: { discordUrl?: string; youtubeUrl?: string; websiteUrl?: string } = {};
if (faker.datatype.boolean()) socialLinks.discordUrl = faker.internet.url();
if (faker.datatype.boolean()) socialLinks.youtubeUrl = faker.internet.url();
if (faker.datatype.boolean()) socialLinks.websiteUrl = faker.internet.url();
const leagueData: {
id: string;
name: string;
description: string;
ownerId: string;
settings: {
pointsSystem: 'f1-2024' | 'indycar' | 'custom';
maxDrivers: number;
sessionDuration: number;
qualifyingFormat: 'open' | 'single-lap';
};
createdAt: Date;
socialLinks?: { discordUrl?: string; youtubeUrl?: string; websiteUrl?: string };
} = {
id: `league-${i}`,
name: faker.company.name() + ' Racing League',
description: faker.lorem.sentences(2),
ownerId: owner.id.toString(),
settings: {
pointsSystem: faker.helpers.arrayElement(pointsSystems),
maxDrivers: faker.number.int({ min: 20, max: 50 }),
sessionDuration: faker.number.int({ min: 30, max: 180 }),
qualifyingFormat: faker.helpers.arrayElement(qualifyingFormats),
},
createdAt: faker.date.past({ years: 2, refDate: this.baseDate }),
};
if (Object.keys(socialLinks).length > 0) {
leagueData.socialLinks = socialLinks;
}
return League.create(leagueData);
});
}
}