This commit is contained in:
2025-12-11 13:50:38 +01:00
parent e4c1be628d
commit c7e5de40d6
212 changed files with 2965 additions and 763 deletions

View File

@@ -1,6 +1,8 @@
import type { IValueObject } from '@gridpilot/shared/domain';
/**
* Value Object: UserRating
*
*
* Multi-dimensional rating system for users covering:
* - Driver skill: racing ability, lap times, consistency
* - Admin competence: league management, event organization
@@ -37,27 +39,47 @@ const DEFAULT_DIMENSION: RatingDimension = {
lastUpdated: new Date(),
};
export class UserRating {
readonly userId: string;
readonly driver: RatingDimension;
readonly admin: RatingDimension;
readonly steward: RatingDimension;
readonly trust: RatingDimension;
readonly fairness: RatingDimension;
readonly overallReputation: number;
readonly createdAt: Date;
readonly updatedAt: Date;
export class UserRating implements IValueObject<UserRatingProps> {
readonly props: UserRatingProps;
private constructor(props: UserRatingProps) {
this.userId = props.userId;
this.driver = props.driver;
this.admin = props.admin;
this.steward = props.steward;
this.trust = props.trust;
this.fairness = props.fairness;
this.overallReputation = props.overallReputation;
this.createdAt = props.createdAt;
this.updatedAt = props.updatedAt;
this.props = props;
}
get userId(): string {
return this.props.userId;
}
get driver(): RatingDimension {
return this.props.driver;
}
get admin(): RatingDimension {
return this.props.admin;
}
get steward(): RatingDimension {
return this.props.steward;
}
get trust(): RatingDimension {
return this.props.trust;
}
get fairness(): RatingDimension {
return this.props.fairness;
}
get overallReputation(): number {
return this.props.overallReputation;
}
get createdAt(): Date {
return this.props.createdAt;
}
get updatedAt(): Date {
return this.props.updatedAt;
}
static create(userId: string): UserRating {
@@ -83,6 +105,10 @@ export class UserRating {
return new UserRating(props);
}
equals(other: IValueObject<UserRatingProps>): boolean {
return this.props.userId === other.props.userId;
}
/**
* Update driver rating based on race performance
*/
@@ -241,14 +267,14 @@ export class UserRating {
private withUpdates(updates: Partial<UserRatingProps>): UserRating {
const newRating = new UserRating({
...this,
...this.props,
...updates,
updatedAt: new Date(),
});
// Recalculate overall reputation
return new UserRating({
...newRating,
...newRating.props,
overallReputation: newRating.calculateOverallReputation(),
});
}