team rating
This commit is contained in:
44
core/racing/domain/value-objects/TeamRatingValue.ts
Normal file
44
core/racing/domain/value-objects/TeamRatingValue.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import type { IValueObject } from '@core/shared/domain';
|
||||
import { RacingDomainValidationError } from '../errors/RacingDomainError';
|
||||
|
||||
export interface TeamRatingValueProps {
|
||||
value: number;
|
||||
}
|
||||
|
||||
export class TeamRatingValue implements IValueObject<TeamRatingValueProps> {
|
||||
readonly value: number;
|
||||
|
||||
private constructor(value: number) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
static create(value: number): TeamRatingValue {
|
||||
if (typeof value !== 'number' || isNaN(value)) {
|
||||
throw new RacingDomainValidationError('Team rating value must be a valid number');
|
||||
}
|
||||
|
||||
if (value < 0 || value > 100) {
|
||||
throw new RacingDomainValidationError(
|
||||
`Team rating value must be between 0 and 100, got: ${value}`
|
||||
);
|
||||
}
|
||||
|
||||
return new TeamRatingValue(value);
|
||||
}
|
||||
|
||||
get props(): TeamRatingValueProps {
|
||||
return { value: this.value };
|
||||
}
|
||||
|
||||
equals(other: IValueObject<TeamRatingValueProps>): boolean {
|
||||
return this.value === other.props.value;
|
||||
}
|
||||
|
||||
toNumber(): number {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return this.value.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user