This commit is contained in:
2025-12-16 21:05:01 +01:00
parent f61e3a4e5a
commit 7532c7ed6d
207 changed files with 7861 additions and 2606 deletions

View File

@@ -1,9 +1,12 @@
import type { UseCase } from '@core/shared/application/UseCase';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { INotificationService } from '../../../notifications/application/ports/INotificationService';
import type { IRaceEventRepository } from '../../domain/repositories/IRaceEventRepository';
import type { IResultRepository } from '../../domain/repositories/IResultRepository';
import type { MainRaceCompletedEvent } from '../../domain/events/MainRaceCompleted';
import type { NotificationType } from '../../../notifications/domain/types/NotificationTypes';
import type { RaceEvent } from '../../domain/entities/RaceEvent';
import type { Result as RaceResult } from '../../domain/entities/Result';
/**
* Use Case: SendPerformanceSummaryUseCase
@@ -11,21 +14,21 @@ import type { NotificationType } from '../../../notifications/domain/types/Notif
* Triggered by MainRaceCompleted domain event.
* Sends immediate performance summary modal notifications to all drivers who participated in the main race.
*/
export class SendPerformanceSummaryUseCase implements UseCase<MainRaceCompletedEvent, void, void, void> {
export class SendPerformanceSummaryUseCase {
constructor(
private readonly notificationService: INotificationService,
private readonly raceEventRepository: IRaceEventRepository,
private readonly resultRepository: IResultRepository,
) {}
async execute(event: MainRaceCompletedEvent): Promise<void> {
async execute(event: MainRaceCompletedEvent): Promise<Result<void, ApplicationErrorCode<never>>> {
const { raceEventId, sessionId, leagueId, driverIds } = event.eventData;
// Get race event to include context
const raceEvent = await this.raceEventRepository.findById(raceEventId);
if (!raceEvent) {
console.warn(`RaceEvent ${raceEventId} not found, skipping performance summary notifications`);
return;
// RaceEvent not found, skip
return Result.ok(undefined);
}
// Get results for the main race session to calculate performance data
@@ -42,12 +45,14 @@ export class SendPerformanceSummaryUseCase implements UseCase<MainRaceCompletedE
leagueId
);
}
return Result.ok(undefined);
}
private async sendPerformanceSummaryNotification(
driverId: string,
raceEvent: any, // RaceEvent type
driverResult: any, // Result type
raceEvent: RaceEvent,
driverResult: RaceResult | undefined,
leagueId: string
): Promise<void> {
const position = driverResult?.position ?? 'DNF';
@@ -77,7 +82,7 @@ export class SendPerformanceSummaryUseCase implements UseCase<MainRaceCompletedE
urgency: 'modal',
data: {
raceEventId: raceEvent.id,
sessionId: raceEvent.getMainRaceSession()?.id,
sessionId: raceEvent.getMainRaceSession()?.id ?? '',
leagueId,
position,
positionChange,