seed data

This commit is contained in:
2025-12-30 18:33:15 +01:00
parent 83371ea839
commit 92226800df
306 changed files with 1753 additions and 501 deletions

View File

@@ -20,6 +20,7 @@ export class Driver implements IEntity<string> {
readonly country: CountryCode;
readonly bio: DriverBio | undefined;
readonly joinedAt: JoinedAt;
readonly category: string | undefined;
private constructor(props: {
id: string;
@@ -28,6 +29,7 @@ export class Driver implements IEntity<string> {
country: CountryCode;
bio?: DriverBio;
joinedAt: JoinedAt;
category?: string;
}) {
this.id = props.id;
this.iracingId = props.iracingId;
@@ -35,6 +37,7 @@ export class Driver implements IEntity<string> {
this.country = props.country;
this.bio = props.bio;
this.joinedAt = props.joinedAt;
this.category = props.category;
}
/**
@@ -47,19 +50,36 @@ export class Driver implements IEntity<string> {
country: string;
bio?: string;
joinedAt?: Date;
category?: string;
}): Driver {
if (!props.id || props.id.trim().length === 0) {
throw new RacingDomainValidationError('Driver ID is required');
}
return new Driver({
const driverProps: {
id: string;
iracingId: IRacingId;
name: DriverName;
country: CountryCode;
bio?: DriverBio;
joinedAt: JoinedAt;
category?: string;
} = {
id: props.id,
iracingId: IRacingId.create(props.iracingId),
name: DriverName.create(props.name),
country: CountryCode.create(props.country),
...(props.bio !== undefined ? { bio: DriverBio.create(props.bio) } : {}),
joinedAt: JoinedAt.create(props.joinedAt ?? new Date()),
});
};
if (props.bio !== undefined) {
driverProps.bio = DriverBio.create(props.bio);
}
if (props.category !== undefined) {
driverProps.category = props.category;
}
return new Driver(driverProps);
}
static rehydrate(props: {
@@ -69,15 +89,32 @@ export class Driver implements IEntity<string> {
country: string;
bio?: string;
joinedAt: Date;
category?: string;
}): Driver {
return new Driver({
const driverProps: {
id: string;
iracingId: IRacingId;
name: DriverName;
country: CountryCode;
bio?: DriverBio;
joinedAt: JoinedAt;
category?: string;
} = {
id: props.id,
iracingId: IRacingId.create(props.iracingId),
name: DriverName.create(props.name),
country: CountryCode.create(props.country),
...(props.bio !== undefined ? { bio: DriverBio.create(props.bio) } : {}),
joinedAt: JoinedAt.create(props.joinedAt),
});
};
if (props.bio !== undefined) {
driverProps.bio = DriverBio.create(props.bio);
}
if (props.category !== undefined) {
driverProps.category = props.category;
}
return new Driver(driverProps);
}
/**
@@ -87,18 +124,36 @@ export class Driver implements IEntity<string> {
name: string;
country: string;
bio: string | undefined;
category: string | undefined;
}>): Driver {
const nextName = 'name' in props ? DriverName.create(props.name!) : this.name;
const nextCountry = 'country' in props ? CountryCode.create(props.country!) : this.country;
const nextBio = 'bio' in props ? (props.bio ? DriverBio.create(props.bio) : undefined) : this.bio;
const nextCategory = 'category' in props ? props.category : this.category;
return new Driver({
const driverProps: {
id: string;
iracingId: IRacingId;
name: DriverName;
country: CountryCode;
bio?: DriverBio;
joinedAt: JoinedAt;
category?: string;
} = {
id: this.id,
iracingId: this.iracingId,
name: nextName,
country: nextCountry,
...(nextBio !== undefined ? { bio: nextBio } : {}),
joinedAt: this.joinedAt,
});
};
if (nextBio !== undefined) {
driverProps.bio = nextBio;
}
if (nextCategory !== undefined) {
driverProps.category = nextCategory;
}
return new Driver(driverProps);
}
}