Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m51s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
56 lines
1.1 KiB
TypeScript
56 lines
1.1 KiB
TypeScript
/**
|
|
* Rating Entity
|
|
*
|
|
* Represents a driver's rating calculated after a race.
|
|
*/
|
|
|
|
import { DriverId } from '../../racing/domain/entities/DriverId';
|
|
import { RaceId } from '../../racing/domain/entities/RaceId';
|
|
import { RatingComponents } from './RatingComponents';
|
|
|
|
export interface RatingProps {
|
|
driverId: DriverId;
|
|
raceId: RaceId;
|
|
rating: number;
|
|
components: RatingComponents;
|
|
timestamp: Date;
|
|
}
|
|
|
|
export class Rating {
|
|
private constructor(private readonly props: RatingProps) {}
|
|
|
|
static create(props: RatingProps): Rating {
|
|
return new Rating(props);
|
|
}
|
|
|
|
get driverId(): DriverId {
|
|
return this.props.driverId;
|
|
}
|
|
|
|
get raceId(): RaceId {
|
|
return this.props.raceId;
|
|
}
|
|
|
|
get rating(): number {
|
|
return this.props.rating;
|
|
}
|
|
|
|
get components(): RatingComponents {
|
|
return this.props.components;
|
|
}
|
|
|
|
get timestamp(): Date {
|
|
return this.props.timestamp;
|
|
}
|
|
|
|
toJSON(): Record<string, any> {
|
|
return {
|
|
driverId: this.driverId.toString(),
|
|
raceId: this.raceId.toString(),
|
|
rating: this.rating,
|
|
components: this.components,
|
|
timestamp: this.timestamp.toISOString(),
|
|
};
|
|
}
|
|
}
|