website refactor
This commit is contained in:
57
apps/website/lib/mutations/leagues/ProtestReviewMutation.ts
Normal file
57
apps/website/lib/mutations/leagues/ProtestReviewMutation.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { ProtestService } from '@/lib/services/protests/ProtestService';
|
||||
import { ProtestsApiClient } from '@/lib/api/protests/ProtestsApiClient';
|
||||
import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorReporter';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import type { ApplyPenaltyCommandDTO } from '@/lib/types/generated/ApplyPenaltyCommandDTO';
|
||||
import type { RequestProtestDefenseCommandDTO } from '@/lib/types/generated/RequestProtestDefenseCommandDTO';
|
||||
|
||||
/**
|
||||
* ProtestReviewMutation
|
||||
*
|
||||
* Framework-agnostic mutation for protest review operations.
|
||||
* Can be called from Server Actions or other contexts.
|
||||
*/
|
||||
export class ProtestReviewMutation {
|
||||
private service: ProtestService;
|
||||
|
||||
constructor() {
|
||||
// Manual wiring for serverless
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_URL || '';
|
||||
const errorReporter = new ConsoleErrorReporter();
|
||||
const logger = new ConsoleLogger();
|
||||
const apiClient = new ProtestsApiClient(baseUrl, errorReporter, logger);
|
||||
|
||||
this.service = new ProtestService(apiClient);
|
||||
}
|
||||
|
||||
async applyPenalty(input: ApplyPenaltyCommandDTO): Promise<Result<void, string>> {
|
||||
try {
|
||||
await this.service.applyPenalty(input);
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
console.error('applyPenalty failed:', error);
|
||||
return Result.err('Failed to apply penalty');
|
||||
}
|
||||
}
|
||||
|
||||
async requestDefense(input: RequestProtestDefenseCommandDTO): Promise<Result<void, string>> {
|
||||
try {
|
||||
await this.service.requestDefense(input);
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
console.error('requestDefense failed:', error);
|
||||
return Result.err('Failed to request defense');
|
||||
}
|
||||
}
|
||||
|
||||
async reviewProtest(input: { protestId: string; stewardId: string; decision: string; decisionNotes: string }): Promise<Result<void, string>> {
|
||||
try {
|
||||
await this.service.reviewProtest(input as any);
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
console.error('reviewProtest failed:', error);
|
||||
return Result.err('Failed to review protest');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user