harden media

This commit is contained in:
2025-12-31 15:39:28 +01:00
parent 92226800df
commit 8260bf7baf
413 changed files with 8361 additions and 1544 deletions

View File

@@ -12,6 +12,7 @@ import { DriverName } from '../value-objects/driver/DriverName';
import { CountryCode } from '../value-objects/CountryCode';
import { DriverBio } from '../value-objects/driver/DriverBio';
import { JoinedAt } from '../value-objects/JoinedAt';
import { MediaReference } from '@core/domain/media/MediaReference';
export class Driver implements IEntity<string> {
readonly id: string;
@@ -21,6 +22,7 @@ export class Driver implements IEntity<string> {
readonly bio: DriverBio | undefined;
readonly joinedAt: JoinedAt;
readonly category: string | undefined;
readonly avatarRef: MediaReference;
private constructor(props: {
id: string;
@@ -30,6 +32,7 @@ export class Driver implements IEntity<string> {
bio?: DriverBio;
joinedAt: JoinedAt;
category?: string;
avatarRef: MediaReference;
}) {
this.id = props.id;
this.iracingId = props.iracingId;
@@ -38,6 +41,7 @@ export class Driver implements IEntity<string> {
this.bio = props.bio;
this.joinedAt = props.joinedAt;
this.category = props.category;
this.avatarRef = props.avatarRef;
}
/**
@@ -51,6 +55,7 @@ export class Driver implements IEntity<string> {
bio?: string;
joinedAt?: Date;
category?: string;
avatarRef?: MediaReference;
}): Driver {
if (!props.id || props.id.trim().length === 0) {
throw new RacingDomainValidationError('Driver ID is required');
@@ -64,12 +69,14 @@ export class Driver implements IEntity<string> {
bio?: DriverBio;
joinedAt: JoinedAt;
category?: string;
avatarRef: MediaReference;
} = {
id: props.id,
iracingId: IRacingId.create(props.iracingId),
name: DriverName.create(props.name),
country: CountryCode.create(props.country),
joinedAt: JoinedAt.create(props.joinedAt ?? new Date()),
avatarRef: props.avatarRef ?? MediaReference.createSystemDefault('avatar'),
};
if (props.bio !== undefined) {
@@ -90,6 +97,7 @@ export class Driver implements IEntity<string> {
bio?: string;
joinedAt: Date;
category?: string;
avatarRef?: MediaReference;
}): Driver {
const driverProps: {
id: string;
@@ -99,12 +107,14 @@ export class Driver implements IEntity<string> {
bio?: DriverBio;
joinedAt: JoinedAt;
category?: string;
avatarRef: MediaReference;
} = {
id: props.id,
iracingId: IRacingId.create(props.iracingId),
name: DriverName.create(props.name),
country: CountryCode.create(props.country),
joinedAt: JoinedAt.create(props.joinedAt),
avatarRef: props.avatarRef ?? MediaReference.createSystemDefault('avatar'),
};
if (props.bio !== undefined) {
@@ -125,11 +135,13 @@ export class Driver implements IEntity<string> {
country: string;
bio: string | undefined;
category: string | undefined;
avatarRef: MediaReference;
}>): 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;
const nextAvatarRef = 'avatarRef' in props ? props.avatarRef! : this.avatarRef;
const driverProps: {
id: string;
@@ -139,12 +151,14 @@ export class Driver implements IEntity<string> {
bio?: DriverBio;
joinedAt: JoinedAt;
category?: string;
avatarRef: MediaReference;
} = {
id: this.id,
iracingId: this.iracingId,
name: nextName,
country: nextCountry,
joinedAt: this.joinedAt,
avatarRef: nextAvatarRef,
};
if (nextBio !== undefined) {