36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
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';
|
|
import type { CreateLeagueInputDTO } from '@/lib/types/generated/CreateLeagueInputDTO';
|
|
|
|
/**
|
|
* CreateLeagueMutation
|
|
*
|
|
* Framework-agnostic mutation for creating leagues.
|
|
* Can be called from Server Actions or other contexts.
|
|
*/
|
|
export class CreateLeagueMutation {
|
|
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();
|
|
}
|
|
|
|
async execute(input: CreateLeagueInputDTO): Promise<Result<string, string>> {
|
|
try {
|
|
const result = await this.service.createLeague(input);
|
|
return Result.ok(result.leagueId);
|
|
} catch (error) {
|
|
console.error('CreateLeagueMutation failed:', error);
|
|
return Result.err('Failed to create league');
|
|
}
|
|
}
|
|
} |