refactor
This commit is contained in:
29
core/racing/domain/value-objects/driver/DriverBio.ts
Normal file
29
core/racing/domain/value-objects/driver/DriverBio.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { RacingDomainValidationError } from '../../errors/RacingDomainError';
|
||||
import type { IValueObject } from '@core/shared/domain';
|
||||
|
||||
export interface DriverBioProps {
|
||||
value: string;
|
||||
}
|
||||
|
||||
export class DriverBio implements IValueObject<DriverBioProps> {
|
||||
private constructor(private readonly value: string) {}
|
||||
|
||||
static create(value: string): DriverBio {
|
||||
if (value.length > 500) {
|
||||
throw new RacingDomainValidationError('Driver bio cannot exceed 500 characters');
|
||||
}
|
||||
return new DriverBio(value);
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
equals(other: IValueObject<DriverBioProps>): boolean {
|
||||
return this.props.value === other.props.value;
|
||||
}
|
||||
|
||||
get props(): DriverBioProps {
|
||||
return { value: this.value };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user