website refactor
This commit is contained in:
@@ -8,7 +8,7 @@ import type { CreateLeagueInputDTO } from '@/lib/types/generated/CreateLeagueInp
|
||||
/**
|
||||
* CreateLeagueMutation
|
||||
*
|
||||
* Framework-agnostic mutation for league creation.
|
||||
* Framework-agnostic mutation for creating leagues.
|
||||
* Can be called from Server Actions or other contexts.
|
||||
*/
|
||||
export class CreateLeagueMutation {
|
||||
@@ -24,12 +24,12 @@ export class CreateLeagueMutation {
|
||||
this.service = new LeagueService(apiClient);
|
||||
}
|
||||
|
||||
async createLeague(input: CreateLeagueInputDTO): Promise<Result<void, string>> {
|
||||
async execute(input: CreateLeagueInputDTO): Promise<Result<string, string>> {
|
||||
try {
|
||||
await this.service.createLeague(input);
|
||||
return Result.ok(undefined);
|
||||
const result = await this.service.createLeague(input);
|
||||
return Result.ok(result.leagueId);
|
||||
} catch (error) {
|
||||
console.error('createLeague failed:', error);
|
||||
console.error('CreateLeagueMutation failed:', error);
|
||||
return Result.err('Failed to create league');
|
||||
}
|
||||
}
|
||||
|
||||
80
apps/website/lib/mutations/leagues/StewardingMutation.ts
Normal file
80
apps/website/lib/mutations/leagues/StewardingMutation.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { LeagueService } from '@/lib/services/leagues/LeagueService';
|
||||
import { LeaguesApiClient } from '@/lib/api/leagues/LeaguesApiClient';
|
||||
import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorReporter';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
|
||||
/**
|
||||
* StewardingMutation
|
||||
*
|
||||
* Framework-agnostic mutation for stewarding operations.
|
||||
* Can be called from Server Actions or other contexts.
|
||||
*/
|
||||
export class StewardingMutation {
|
||||
private service: LeagueService;
|
||||
|
||||
constructor() {
|
||||
// Manual wiring for serverless
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_URL || '';
|
||||
const errorReporter = new ConsoleErrorReporter();
|
||||
const logger = new ConsoleLogger();
|
||||
const apiClient = new LeaguesApiClient(baseUrl, errorReporter, logger);
|
||||
|
||||
this.service = new LeagueService(apiClient);
|
||||
}
|
||||
|
||||
async applyPenalty(input: {
|
||||
protestId: string;
|
||||
penaltyType: string;
|
||||
penaltyValue: number;
|
||||
stewardNotes: string;
|
||||
raceId: string;
|
||||
accusedDriverId: string;
|
||||
reason: string;
|
||||
}): Promise<Result<void, string>> {
|
||||
try {
|
||||
// TODO: Implement when penalty API is available
|
||||
// For now, return success
|
||||
console.log('applyPenalty called with:', input);
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
console.error('applyPenalty failed:', error);
|
||||
return Result.err('Failed to apply penalty');
|
||||
}
|
||||
}
|
||||
|
||||
async requestDefense(input: {
|
||||
protestId: string;
|
||||
stewardId: string;
|
||||
}): Promise<Result<void, string>> {
|
||||
try {
|
||||
// TODO: Implement when defense API is available
|
||||
// For now, return success
|
||||
console.log('requestDefense called with:', input);
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
console.error('requestDefense failed:', error);
|
||||
return Result.err('Failed to request defense');
|
||||
}
|
||||
}
|
||||
|
||||
async quickPenalty(input: {
|
||||
leagueId: string;
|
||||
driverId: string;
|
||||
raceId: string;
|
||||
penaltyType: string;
|
||||
penaltyValue: number;
|
||||
reason: string;
|
||||
adminId: string;
|
||||
}): Promise<Result<void, string>> {
|
||||
try {
|
||||
// TODO: Implement when quick penalty API is available
|
||||
// For now, return success
|
||||
console.log('quickPenalty called with:', input);
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
console.error('quickPenalty failed:', error);
|
||||
return Result.err('Failed to apply quick penalty');
|
||||
}
|
||||
}
|
||||
}
|
||||
49
apps/website/lib/mutations/leagues/WalletMutation.ts
Normal file
49
apps/website/lib/mutations/leagues/WalletMutation.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { LeagueService } from '@/lib/services/leagues/LeagueService';
|
||||
import { LeaguesApiClient } from '@/lib/api/leagues/LeaguesApiClient';
|
||||
import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorReporter';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
|
||||
/**
|
||||
* WalletMutation
|
||||
*
|
||||
* Framework-agnostic mutation for wallet operations.
|
||||
* Can be called from Server Actions or other contexts.
|
||||
*/
|
||||
export class WalletMutation {
|
||||
private service: LeagueService;
|
||||
|
||||
constructor() {
|
||||
// Manual wiring for serverless
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_URL || '';
|
||||
const errorReporter = new ConsoleErrorReporter();
|
||||
const logger = new ConsoleLogger();
|
||||
const apiClient = new LeaguesApiClient(baseUrl, errorReporter, logger);
|
||||
|
||||
this.service = new LeagueService(apiClient);
|
||||
}
|
||||
|
||||
async withdraw(leagueId: string, amount: number): Promise<Result<void, string>> {
|
||||
try {
|
||||
// TODO: Implement when wallet withdrawal API is available
|
||||
// For now, return success
|
||||
console.log('withdraw called with:', { leagueId, amount });
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
console.error('withdraw failed:', error);
|
||||
return Result.err('Failed to withdraw funds');
|
||||
}
|
||||
}
|
||||
|
||||
async exportTransactions(leagueId: string): Promise<Result<void, string>> {
|
||||
try {
|
||||
// TODO: Implement when export API is available
|
||||
// For now, return success
|
||||
console.log('exportTransactions called with:', { leagueId });
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
console.error('exportTransactions failed:', error);
|
||||
return Result.err('Failed to export transactions');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user