seed data
This commit is contained in:
65
adapters/bootstrap/racing/RacingMembershipFactory.ts
Normal file
65
adapters/bootstrap/racing/RacingMembershipFactory.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { Driver } from '@core/racing/domain/entities/Driver';
|
||||
import { League } from '@core/racing/domain/entities/League';
|
||||
import { LeagueMembership } from '@core/racing/domain/entities/LeagueMembership';
|
||||
import { Race } from '@core/racing/domain/entities/Race';
|
||||
import { RaceRegistration } from '@core/racing/domain/entities/RaceRegistration';
|
||||
|
||||
export class RacingMembershipFactory {
|
||||
constructor(private readonly baseDate: Date) {}
|
||||
|
||||
createLeagueMemberships(drivers: Driver[], leagues: League[]): LeagueMembership[] {
|
||||
const memberships: LeagueMembership[] = [];
|
||||
|
||||
for (const driver of drivers) {
|
||||
const driverId = driver.id;
|
||||
|
||||
memberships.push(
|
||||
LeagueMembership.create({
|
||||
leagueId: 'league-5',
|
||||
driverId,
|
||||
role: driverId === 'driver-1' ? 'owner' : 'member',
|
||||
status: 'active',
|
||||
joinedAt: this.addDays(this.baseDate, -60),
|
||||
}),
|
||||
);
|
||||
|
||||
const driverNumber = Number(driverId.split('-')[1]);
|
||||
const extraLeague = leagues[(driverNumber % (leagues.length - 1)) + 1];
|
||||
|
||||
if (extraLeague) {
|
||||
memberships.push(
|
||||
LeagueMembership.create({
|
||||
leagueId: extraLeague.id.toString(),
|
||||
driverId,
|
||||
role: 'member',
|
||||
status: 'active',
|
||||
joinedAt: this.addDays(this.baseDate, -40),
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return memberships;
|
||||
}
|
||||
|
||||
createRaceRegistrations(races: Race[]): RaceRegistration[] {
|
||||
const registrations: RaceRegistration[] = [];
|
||||
|
||||
const upcomingDemoLeague = races.filter((r) => r.status === 'scheduled' && r.leagueId === 'league-5').slice(0, 3);
|
||||
|
||||
for (const race of upcomingDemoLeague) {
|
||||
registrations.push(
|
||||
RaceRegistration.create({
|
||||
raceId: race.id,
|
||||
driverId: 'driver-1',
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return registrations;
|
||||
}
|
||||
|
||||
private addDays(date: Date, days: number): Date {
|
||||
return new Date(date.getTime() + days * 24 * 60 * 60 * 1000);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user