refactor
This commit is contained in:
@@ -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 { RaceEventStewardingClosedEvent } from '../../domain/events/RaceEventStewardingClosed';
|
||||
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: SendFinalResultsUseCase
|
||||
@@ -12,28 +15,28 @@ import type { NotificationType } from '../../../notifications/domain/types/Notif
|
||||
* Sends final results modal notifications to all drivers who participated,
|
||||
* including any penalty adjustments applied during stewarding.
|
||||
*/
|
||||
export class SendFinalResultsUseCase implements UseCase<RaceEventStewardingClosedEvent, void, void, void> {
|
||||
export class SendFinalResultsUseCase {
|
||||
constructor(
|
||||
private readonly notificationService: INotificationService,
|
||||
private readonly raceEventRepository: IRaceEventRepository,
|
||||
private readonly resultRepository: IResultRepository,
|
||||
) {}
|
||||
|
||||
async execute(event: RaceEventStewardingClosedEvent): Promise<void> {
|
||||
async execute(event: RaceEventStewardingClosedEvent): Promise<Result<void, ApplicationErrorCode<never>>> {
|
||||
const { raceEventId, leagueId, driverIds, hadPenaltiesApplied } = event.eventData;
|
||||
|
||||
// Get race event to include context
|
||||
const raceEvent = await this.raceEventRepository.findById(raceEventId);
|
||||
if (!raceEvent) {
|
||||
console.warn(`RaceEvent ${raceEventId} not found, skipping final results notifications`);
|
||||
return;
|
||||
// RaceEvent not found, skip
|
||||
return Result.ok(undefined);
|
||||
}
|
||||
|
||||
// Get final results for the main race session
|
||||
const mainRaceSession = raceEvent.getMainRaceSession();
|
||||
if (!mainRaceSession) {
|
||||
console.warn(`No main race session found for RaceEvent ${raceEventId}`);
|
||||
return;
|
||||
// No main race session, skip
|
||||
return Result.ok(undefined);
|
||||
}
|
||||
|
||||
const results = await this.resultRepository.findByRaceId(mainRaceSession.id);
|
||||
@@ -50,12 +53,14 @@ export class SendFinalResultsUseCase implements UseCase<RaceEventStewardingClose
|
||||
hadPenaltiesApplied
|
||||
);
|
||||
}
|
||||
|
||||
return Result.ok(undefined);
|
||||
}
|
||||
|
||||
private async sendFinalResultsNotification(
|
||||
driverId: string,
|
||||
raceEvent: any, // RaceEvent type
|
||||
driverResult: any, // Result type
|
||||
raceEvent: RaceEvent,
|
||||
driverResult: RaceResult | undefined,
|
||||
leagueId: string,
|
||||
hadPenaltiesApplied: boolean
|
||||
): Promise<void> {
|
||||
@@ -88,7 +93,7 @@ export class SendFinalResultsUseCase implements UseCase<RaceEventStewardingClose
|
||||
urgency: 'modal',
|
||||
data: {
|
||||
raceEventId: raceEvent.id,
|
||||
sessionId: raceEvent.getMainRaceSession()?.id,
|
||||
sessionId: raceEvent.getMainRaceSession()?.id ?? '',
|
||||
leagueId,
|
||||
position,
|
||||
positionChange,
|
||||
|
||||
Reference in New Issue
Block a user