refactor
This commit is contained in:
@@ -8,15 +8,15 @@ import { Standing } from '../../domain/entities/Standing';
|
||||
import { RaceResultGenerator } from '../utils/RaceResultGenerator';
|
||||
import { RatingUpdateService } from '@core/identity/domain/services/RatingUpdateService';
|
||||
import type { AsyncUseCase } from '@core/shared/application';
|
||||
import { Result as SharedResult } from '@core/shared/result/Result';
|
||||
import { RacingDomainValidationError } from '../../domain/errors/RacingDomainError';
|
||||
import { Result as SharedResult } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { CompleteRaceCommandDTO } from '../dto/CompleteRaceCommandDTO';
|
||||
|
||||
/**
|
||||
* Enhanced CompleteRaceUseCase that includes rating updates
|
||||
*/
|
||||
export class CompleteRaceUseCaseWithRatings
|
||||
implements AsyncUseCase<CompleteRaceCommandDTO, SharedResult<void, RacingDomainValidationError>> {
|
||||
implements AsyncUseCase<CompleteRaceCommandDTO, void, string> {
|
||||
constructor(
|
||||
private readonly raceRepository: IRaceRepository,
|
||||
private readonly raceRegistrationRepository: IRaceRegistrationRepository,
|
||||
@@ -26,19 +26,19 @@ export class CompleteRaceUseCaseWithRatings
|
||||
private readonly ratingUpdateService: RatingUpdateService,
|
||||
) {}
|
||||
|
||||
async execute(command: CompleteRaceCommandDTO): Promise<SharedResult<void, RacingDomainValidationError>> {
|
||||
async execute(command: CompleteRaceCommandDTO): Promise<SharedResult<void, ApplicationErrorCode<string>>> {
|
||||
try {
|
||||
const { raceId } = command;
|
||||
|
||||
const race = await this.raceRepository.findById(raceId);
|
||||
if (!race) {
|
||||
return SharedResult.err(new RacingDomainValidationError('Race not found'));
|
||||
return SharedResult.err({ code: 'RACE_NOT_FOUND' });
|
||||
}
|
||||
|
||||
// Get registered drivers for this race
|
||||
const registeredDriverIds = await this.raceRegistrationRepository.getRegisteredDrivers(raceId);
|
||||
if (registeredDriverIds.length === 0) {
|
||||
return SharedResult.err(new RacingDomainValidationError('Cannot complete race with no registered drivers'));
|
||||
return SharedResult.err({ code: 'NO_REGISTERED_DRIVERS' });
|
||||
}
|
||||
|
||||
// Get driver ratings
|
||||
@@ -63,8 +63,8 @@ export class CompleteRaceUseCaseWithRatings
|
||||
await this.raceRepository.update(completedRace);
|
||||
|
||||
return SharedResult.ok(undefined);
|
||||
} catch (error) {
|
||||
return SharedResult.err(new RacingDomainValidationError(error instanceof Error ? error.message : 'Unknown error'));
|
||||
} catch {
|
||||
return SharedResult.err({ code: 'UNKNOWN_ERROR' });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user