fix seeds
This commit is contained in:
@@ -1,100 +1,58 @@
|
||||
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) {}
|
||||
constructor(
|
||||
private readonly baseDate: Date,
|
||||
private readonly drivers: Driver[],
|
||||
) {}
|
||||
|
||||
create(): League[] {
|
||||
const createdAtBase = this.baseDate;
|
||||
const leagueCount = 20;
|
||||
const pointsSystems = ['f1-2024', 'indycar', 'custom'] as const;
|
||||
const qualifyingFormats = ['open', 'single-lap'] as const;
|
||||
|
||||
return [
|
||||
League.create({
|
||||
id: 'league-1',
|
||||
name: 'GridPilot Sprint Series',
|
||||
description: 'Weekly sprint races with stable grids.',
|
||||
ownerId: 'driver-1',
|
||||
settings: {
|
||||
pointsSystem: 'f1-2024',
|
||||
maxDrivers: 24,
|
||||
sessionDuration: 60,
|
||||
qualifyingFormat: 'open',
|
||||
},
|
||||
createdAt: this.addDays(createdAtBase, -200),
|
||||
socialLinks: {
|
||||
discordUrl: 'https://discord.gg/gridpilot-demo',
|
||||
youtubeUrl: 'https://youtube.com/@gridpilot-demo',
|
||||
websiteUrl: 'https://gridpilot-demo.example.com',
|
||||
},
|
||||
}),
|
||||
League.create({
|
||||
id: 'league-2',
|
||||
name: 'GridPilot Endurance Cup',
|
||||
description: 'Longer races with strategy and consistency.',
|
||||
ownerId: 'driver-2',
|
||||
settings: {
|
||||
pointsSystem: 'indycar',
|
||||
maxDrivers: 32,
|
||||
sessionDuration: 120,
|
||||
qualifyingFormat: 'open',
|
||||
},
|
||||
createdAt: this.addDays(createdAtBase, -180),
|
||||
socialLinks: { discordUrl: 'https://discord.gg/gridpilot-endurance' },
|
||||
}),
|
||||
League.create({
|
||||
id: 'league-3',
|
||||
name: 'GridPilot Club Ladder',
|
||||
description: 'Casual ladder with fast onboarding.',
|
||||
ownerId: 'driver-3',
|
||||
settings: {
|
||||
pointsSystem: 'f1-2024',
|
||||
maxDrivers: 48,
|
||||
sessionDuration: 45,
|
||||
qualifyingFormat: 'single-lap',
|
||||
},
|
||||
createdAt: this.addDays(createdAtBase, -160),
|
||||
}),
|
||||
League.create({
|
||||
id: 'league-4',
|
||||
name: 'Nordic Night Series',
|
||||
description: 'Evening races with tight fields.',
|
||||
ownerId: 'driver-4',
|
||||
settings: {
|
||||
pointsSystem: 'f1-2024',
|
||||
maxDrivers: 32,
|
||||
sessionDuration: 60,
|
||||
qualifyingFormat: 'open',
|
||||
},
|
||||
createdAt: this.addDays(createdAtBase, -150),
|
||||
}),
|
||||
League.create({
|
||||
id: 'league-5',
|
||||
name: 'Demo League (Admin)',
|
||||
description: 'Primary demo league owned by driver-1.',
|
||||
ownerId: 'driver-1',
|
||||
settings: {
|
||||
pointsSystem: 'f1-2024',
|
||||
maxDrivers: 24,
|
||||
sessionDuration: 60,
|
||||
qualifyingFormat: 'open',
|
||||
},
|
||||
createdAt: this.addDays(createdAtBase, -140),
|
||||
}),
|
||||
League.create({
|
||||
id: 'league-6',
|
||||
name: 'Sim Racing Alliance',
|
||||
description: 'Mixed-format season with community events.',
|
||||
ownerId: 'driver-5',
|
||||
settings: {
|
||||
pointsSystem: 'indycar',
|
||||
maxDrivers: 40,
|
||||
sessionDuration: 90,
|
||||
qualifyingFormat: 'open',
|
||||
},
|
||||
createdAt: this.addDays(createdAtBase, -130),
|
||||
}),
|
||||
];
|
||||
}
|
||||
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();
|
||||
|
||||
private addDays(date: Date, days: number): Date {
|
||||
return new Date(date.getTime() + days * 24 * 60 * 60 * 1000);
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user