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