26 lines
866 B
TypeScript
26 lines
866 B
TypeScript
import { RacingDomainValidationError } from '../errors/RacingDomainError';
|
|
import type { IValueObject } from '@core/shared/domain';
|
|
|
|
export class TrackImageUrl implements IValueObject<string | undefined> {
|
|
private constructor(private readonly value: string | undefined) {}
|
|
|
|
get props(): string | undefined {
|
|
return this.value;
|
|
}
|
|
|
|
static create(value: string | undefined): TrackImageUrl {
|
|
// Allow undefined or valid URL, but for simplicity, just check if string is not empty if provided
|
|
if (value !== undefined && value.trim().length === 0) {
|
|
throw new RacingDomainValidationError('Track image URL cannot be empty string');
|
|
}
|
|
return new TrackImageUrl(value);
|
|
}
|
|
|
|
toString(): string | undefined {
|
|
return this.value;
|
|
}
|
|
|
|
equals(other: IValueObject<string | undefined>): boolean {
|
|
return this.value === other.props;
|
|
}
|
|
} |