This commit is contained in:
2025-12-29 22:27:33 +01:00
parent 3f610c1cb6
commit 7a853d4e43
96 changed files with 14790 additions and 111 deletions

View File

@@ -0,0 +1,44 @@
import type { IValueObject } from '@core/shared/domain';
import { IdentityDomainValidationError } from '../errors/IdentityDomainError';
export interface RatingValueProps {
value: number;
}
export class RatingValue implements IValueObject<RatingValueProps> {
readonly value: number;
private constructor(value: number) {
this.value = value;
}
static create(value: number): RatingValue {
if (typeof value !== 'number' || isNaN(value)) {
throw new IdentityDomainValidationError('Rating value must be a valid number');
}
if (value < 0 || value > 100) {
throw new IdentityDomainValidationError(
`Rating value must be between 0 and 100, got: ${value}`
);
}
return new RatingValue(value);
}
get props(): RatingValueProps {
return { value: this.value };
}
equals(other: IValueObject<RatingValueProps>): boolean {
return this.value === other.props.value;
}
toNumber(): number {
return this.value;
}
toString(): string {
return this.value.toString();
}
}