90 lines
2.8 KiB
TypeScript
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',
|
|
});
|
|
}
|
|
}
|
|
}
|