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:
45
core/rating/application/use-cases/SaveRatingUseCase.ts
Normal file
45
core/rating/application/use-cases/SaveRatingUseCase.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* SaveRatingUseCase
|
||||
*
|
||||
* Saves a driver's rating to the repository.
|
||||
*/
|
||||
|
||||
import { RatingRepository } from '../../ports/RatingRepository';
|
||||
import { Rating } from '../../domain/Rating';
|
||||
import { RatingComponents } from '../../domain/RatingComponents';
|
||||
import { DriverId } from '../../../racing/domain/entities/DriverId';
|
||||
import { RaceId } from '../../../racing/domain/entities/RaceId';
|
||||
|
||||
export interface SaveRatingUseCasePorts {
|
||||
ratingRepository: RatingRepository;
|
||||
}
|
||||
|
||||
export interface SaveRatingRequest {
|
||||
driverId: string;
|
||||
raceId: string;
|
||||
rating: number;
|
||||
components: RatingComponents;
|
||||
}
|
||||
|
||||
export class SaveRatingUseCase {
|
||||
constructor(private readonly ports: SaveRatingUseCasePorts) {}
|
||||
|
||||
async execute(request: SaveRatingRequest): Promise<void> {
|
||||
const { ratingRepository } = this.ports;
|
||||
const { driverId, raceId, rating, components } = request;
|
||||
|
||||
try {
|
||||
const ratingEntity = Rating.create({
|
||||
driverId: DriverId.create(driverId),
|
||||
raceId: RaceId.create(raceId),
|
||||
rating,
|
||||
components,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
|
||||
await ratingRepository.save(ratingEntity);
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to save rating: ${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user