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,16 +1,14 @@
/**
* Application Use Case: ReviewProtestUseCase
*
*
* Allows a steward to review a protest and make a decision (uphold or dismiss).
*/
import type { IProtestRepository } from '../../domain/repositories/IProtestRepository';
import type { IRaceRepository } from '../../domain/repositories/IRaceRepository';
import type { ILeagueMembershipRepository } from '../../domain/repositories/ILeagueMembershipRepository';
import {
EntityNotFoundError,
PermissionDeniedError,
} from '../errors/RacingApplicationError';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
export interface ReviewProtestCommand {
protestId: string;
@@ -26,17 +24,17 @@ export class ReviewProtestUseCase {
private readonly leagueMembershipRepository: ILeagueMembershipRepository,
) {}
async execute(command: ReviewProtestCommand): Promise<void> {
async execute(command: ReviewProtestCommand): Promise<Result<void, ApplicationErrorCode<'PROTEST_NOT_FOUND' | 'RACE_NOT_FOUND' | 'NOT_LEAGUE_ADMIN'>>> {
// Load the protest
const protest = await this.protestRepository.findById(command.protestId);
if (!protest) {
throw new EntityNotFoundError({ entity: 'protest', id: command.protestId });
return Result.err({ code: 'PROTEST_NOT_FOUND' });
}
// Load the race to get league ID
const race = await this.raceRepository.findById(protest.raceId);
if (!race) {
throw new EntityNotFoundError({ entity: 'race', id: protest.raceId });
return Result.err({ code: 'RACE_NOT_FOUND' });
}
// Validate steward has authority (owner or admin of the league)
@@ -44,12 +42,9 @@ export class ReviewProtestUseCase {
const stewardMembership = memberships.find(
m => m.driverId === command.stewardId && m.status === 'active'
);
if (!stewardMembership || (stewardMembership.role !== 'owner' && stewardMembership.role !== 'admin')) {
throw new PermissionDeniedError(
'NOT_LEAGUE_ADMIN',
'Only league owners and admins can review protests',
);
return Result.err({ code: 'NOT_LEAGUE_ADMIN' });
}
// Apply the decision
@@ -61,5 +56,6 @@ export class ReviewProtestUseCase {
}
await this.protestRepository.update(updatedProtest);
return Result.ok(undefined);
}
}