view data fixes
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 7m11s
Contract Testing / contract-snapshot (pull_request) Has been skipped

This commit is contained in:
2026-01-24 23:29:55 +01:00
parent c1750a33dd
commit 1b0a1f4aee
134 changed files with 10380 additions and 415 deletions

View File

@@ -1,31 +1,37 @@
import { Result } from '@/lib/contracts/Result';
import { LeagueService } from '@/lib/services/leagues/LeagueService';
import type { CreateLeagueInputDTO } from '@/lib/types/generated/CreateLeagueInputDTO';
import { DomainError } from '@/lib/contracts/services/Service';
import type { Mutation } from '@/lib/contracts/mutations/Mutation';
/**
* CreateLeagueMutation
*
* Framework-agnostic mutation for creating leagues.
* Can be called from Server Actions or other contexts.
*/
export class CreateLeagueMutation {
private service: LeagueService;
export interface CreateLeagueCommand {
name: string;
description: string;
visibility: string;
ownerId: string;
}
export class CreateLeagueMutation implements Mutation<CreateLeagueCommand, string, DomainError> {
private readonly service: LeagueService;
constructor() {
this.service = new LeagueService();
}
async execute(input: CreateLeagueInputDTO): Promise<Result<string, DomainError>> {
async execute(input: CreateLeagueCommand): Promise<Result<string, DomainError>> {
try {
const result = await this.service.createLeague(input);
if (result.isErr()) {
return Result.err(result.getError());
// LeagueService.createLeague returns any, but we expect { leagueId: string } based on implementation
if (result && typeof result === 'object' && 'leagueId' in result) {
return Result.ok(result.leagueId as string);
}
return Result.ok(result.unwrap().leagueId);
} catch (error: any) {
console.error('CreateLeagueMutation failed:', error);
return Result.err({ type: 'serverError', message: error.message || 'Failed to create league' });
return Result.ok(result as string);
} catch (error) {
return Result.err({
type: 'serverError',
message: error instanceof Error ? error.message : 'Unknown error',
});
}
}
}