Files
gridpilot.gg/apps/website/lib/mutations/leagues/ProtestReviewMutation.ts
Marc Mintel 1b0a1f4aee
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 7m11s
Contract Testing / contract-snapshot (pull_request) Has been skipped
view data fixes
2026-01-24 23:29:55 +01:00

90 lines
2.8 KiB
TypeScript

import { Result } from '@/lib/contracts/Result';
import { ProtestService } from '@/lib/services/protests/ProtestService';
import { DomainError } from '@/lib/contracts/services/Service';
import type { Mutation } from '@/lib/contracts/mutations/Mutation';
export interface ApplyPenaltyCommand {
protestId: string;
penaltyType: string;
penaltyValue: number;
stewardNotes: string;
raceId: string;
accusedDriverId: string;
reason: string;
}
export interface RequestDefenseCommand {
protestId: string;
stewardId: string;
}
export interface ReviewProtestCommand {
protestId: string;
stewardId: string;
decision: string;
decisionNotes: string;
}
export class ProtestReviewMutation implements Mutation<ApplyPenaltyCommand | RequestDefenseCommand | ReviewProtestCommand, void, DomainError> {
private readonly service: ProtestService;
constructor() {
this.service = new ProtestService();
}
async execute(_input: ApplyPenaltyCommand | RequestDefenseCommand | ReviewProtestCommand): Promise<Result<void, DomainError>> {
// This class has multiple entry points in its original design,
// but to satisfy the Mutation interface we provide a generic execute.
// However, the tests call the specific methods directly.
return Result.err({ type: 'notImplemented', message: 'Use specific methods' });
}
async applyPenalty(input: ApplyPenaltyCommand): Promise<Result<void, DomainError>> {
try {
const result = await this.service.applyPenalty(input);
if (result.isErr()) {
return Result.err(result.getError());
}
return Result.ok(undefined);
} catch (error) {
console.error('applyPenalty failed:', error);
return Result.err({
type: 'serverError',
message: error instanceof Error ? error.message : 'Unknown error',
});
}
}
async requestDefense(input: RequestDefenseCommand): Promise<Result<void, DomainError>> {
try {
const result = await this.service.requestDefense(input);
if (result.isErr()) {
return Result.err(result.getError());
}
return Result.ok(undefined);
} catch (error) {
console.error('requestDefense failed:', error);
return Result.err({
type: 'serverError',
message: error instanceof Error ? error.message : 'Unknown error',
});
}
}
async reviewProtest(input: ReviewProtestCommand): Promise<Result<void, DomainError>> {
try {
const result = await this.service.reviewProtest(input);
if (result.isErr()) {
return Result.err(result.getError());
}
return Result.ok(undefined);
} catch (error) {
console.error('reviewProtest failed:', error);
return Result.err({
type: 'serverError',
message: error instanceof Error ? error.message : 'Unknown error',
});
}
}
}