refactor
This commit is contained in:
31
core/racing/domain/value-objects/ImageUrl.ts
Normal file
31
core/racing/domain/value-objects/ImageUrl.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { RacingDomainValidationError } from '../errors/RacingDomainError';
|
||||
import type { IValueObject } from '@core/shared/domain';
|
||||
|
||||
export class ImageUrl implements IValueObject<string> {
|
||||
private constructor(private readonly value: string) {}
|
||||
|
||||
static create(value: string): ImageUrl {
|
||||
if (!value || value.trim().length === 0) {
|
||||
throw new RacingDomainValidationError('Image URL cannot be empty');
|
||||
}
|
||||
// Basic URL validation
|
||||
try {
|
||||
new URL(value);
|
||||
} catch {
|
||||
throw new RacingDomainValidationError('Invalid image URL format');
|
||||
}
|
||||
return new ImageUrl(value.trim());
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
equals(other: IValueObject<string>): boolean {
|
||||
return this.value === other.props;
|
||||
}
|
||||
|
||||
get props(): string {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user