This commit is contained in:
2025-12-17 00:33:13 +01:00
parent 8c67081953
commit f01e01e50c
186 changed files with 9242 additions and 1342 deletions

View File

@@ -0,0 +1,52 @@
import { RacingDomainValidationError } from '../errors/RacingDomainError';
export class LeagueSocialLinks {
readonly discordUrl: string | undefined;
readonly youtubeUrl: string | undefined;
readonly websiteUrl: string | undefined;
private constructor(props: {
discordUrl?: string;
youtubeUrl?: string;
websiteUrl?: string;
}) {
this.discordUrl = props.discordUrl;
this.youtubeUrl = props.youtubeUrl;
this.websiteUrl = props.websiteUrl;
}
static create(props: {
discordUrl?: string;
youtubeUrl?: string;
websiteUrl?: string;
}): LeagueSocialLinks {
// Basic validation, e.g., if provided, must be valid URL
if (props.discordUrl && !this.isValidUrl(props.discordUrl)) {
throw new RacingDomainValidationError('Invalid Discord URL');
}
if (props.youtubeUrl && !this.isValidUrl(props.youtubeUrl)) {
throw new RacingDomainValidationError('Invalid YouTube URL');
}
if (props.websiteUrl && !this.isValidUrl(props.websiteUrl)) {
throw new RacingDomainValidationError('Invalid website URL');
}
return new LeagueSocialLinks(props);
}
private static isValidUrl(url: string): boolean {
try {
new URL(url);
return true;
} catch {
return false;
}
}
equals(other: LeagueSocialLinks): boolean {
return (
this.discordUrl === other.discordUrl &&
this.youtubeUrl === other.youtubeUrl &&
this.websiteUrl === other.websiteUrl
);
}
}