view data fixes
This commit is contained in:
@@ -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',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user