48 lines
1.9 KiB
TypeScript
48 lines
1.9 KiB
TypeScript
import type { TeamRatingEventRepository } from '@core/racing/domain/repositories/TeamRatingEventRepository';
|
|
import type { TeamRatingRepository } from '@core/racing/domain/repositories/TeamRatingRepository';
|
|
import { TeamRatingSnapshotCalculator } from '@core/racing/domain/services/TeamRatingSnapshotCalculator';
|
|
|
|
/**
|
|
* Use Case: RecomputeTeamRatingSnapshotUseCase
|
|
*
|
|
* Recalculates a team's rating snapshot from all events in the ledger.
|
|
* Used for data migration, correction of calculation logic, or audit purposes.
|
|
* Mirrors the RecomputeUserRatingSnapshotUseCase pattern.
|
|
*/
|
|
export class RecomputeTeamRatingSnapshotUseCase {
|
|
constructor(
|
|
private readonly ratingEventRepository: TeamRatingEventRepository,
|
|
private readonly ratingRepository: TeamRatingRepository,
|
|
) {}
|
|
|
|
/**
|
|
* Execute the use case for a specific team
|
|
*
|
|
* @param teamId - The team ID to recompute
|
|
* @returns The recomputed snapshot
|
|
*/
|
|
async execute(teamId: string): Promise<void> {
|
|
// Get all events for the team
|
|
const events = await this.ratingEventRepository.getAllByTeamId(teamId);
|
|
|
|
// Calculate snapshot from all events
|
|
const snapshot = TeamRatingSnapshotCalculator.calculate(teamId, events);
|
|
|
|
// Save the recomputed snapshot
|
|
await this.ratingRepository.save(snapshot);
|
|
}
|
|
|
|
/**
|
|
* Execute the use case for all teams
|
|
*/
|
|
async executeForAllTeams(): Promise<void> {
|
|
// Get all unique team IDs from events
|
|
// This would typically query for all distinct teamIds in the events table
|
|
// For now, we'll use a simpler approach - recompute for teams that have snapshots
|
|
// In a real implementation, you might have a separate method to get all team IDs
|
|
|
|
// Note: This is a simplified implementation
|
|
// In production, you'd want to batch this and handle errors per team
|
|
throw new Error('executeForAllTeams not implemented - needs team ID discovery');
|
|
}
|
|
} |