integration tests
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
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
This commit is contained in:
55
core/rating/domain/Rating.ts
Normal file
55
core/rating/domain/Rating.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* 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(),
|
||||
};
|
||||
}
|
||||
}
|
||||
14
core/rating/domain/RatingComponents.ts
Normal file
14
core/rating/domain/RatingComponents.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* RatingComponents
|
||||
*
|
||||
* Represents the individual components that make up a driver's rating.
|
||||
*/
|
||||
|
||||
export interface RatingComponents {
|
||||
resultsStrength: number;
|
||||
consistency: number;
|
||||
cleanDriving: number;
|
||||
racecraft: number;
|
||||
reliability: number;
|
||||
teamContribution: number;
|
||||
}
|
||||
29
core/rating/domain/events/RatingCalculatedEvent.ts
Normal file
29
core/rating/domain/events/RatingCalculatedEvent.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* RatingCalculatedEvent
|
||||
*
|
||||
* Event published when a driver's rating is calculated.
|
||||
*/
|
||||
|
||||
import { DomainEvent } from '../../../shared/ports/EventPublisher';
|
||||
import { Rating } from '../Rating';
|
||||
|
||||
export class RatingCalculatedEvent implements DomainEvent {
|
||||
readonly type = 'RatingCalculatedEvent';
|
||||
readonly timestamp: Date;
|
||||
|
||||
constructor(private readonly rating: Rating) {
|
||||
this.timestamp = new Date();
|
||||
}
|
||||
|
||||
getRating(): Rating {
|
||||
return this.rating;
|
||||
}
|
||||
|
||||
toJSON(): Record<string, any> {
|
||||
return {
|
||||
type: this.type,
|
||||
timestamp: this.timestamp.toISOString(),
|
||||
rating: this.rating.toJSON(),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user