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,66 +1,89 @@
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 { MembershipRole } from '@/lib/types/MembershipRole';
import type { Mutation } from '@/lib/contracts/mutations/Mutation';
/**
* RosterAdminMutation
*
* Framework-agnostic mutation for roster administration operations.
* Can be called from Server Actions or other contexts.
*/
export class RosterAdminMutation {
private service: LeagueService;
export interface RosterAdminCommand {
leagueId: string;
driverId?: string;
joinRequestId?: string;
role?: MembershipRole;
}
export class RosterAdminMutation implements Mutation<RosterAdminCommand, void, string> {
private readonly service: LeagueService;
constructor() {
// Manual wiring for serverless
const baseUrl = process.env.NEXT_PUBLIC_API_URL || '';
const errorReporter = new ConsoleErrorReporter();
const logger = new ConsoleLogger();
new LeaguesApiClient(baseUrl, errorReporter, logger);
this.service = new LeagueService();
}
async approveJoinRequest(leagueId: string, joinRequestId: string): Promise<Result<void, string>> {
async execute(_command: RosterAdminCommand): Promise<Result<void, string>> {
return Result.err('Use specific methods');
}
async approveJoinRequest(
leagueId: string,
joinRequestId: string,
): Promise<Result<void, string>> {
try {
await this.service.approveJoinRequest(leagueId, joinRequestId);
const result = await this.service.approveJoinRequest(leagueId, joinRequestId);
if (result.isErr()) {
return Result.err('Failed to approve join request');
}
return Result.ok(undefined);
} catch (error) {
console.error('approveJoinRequest failed:', error);
return Result.err('Failed to approve join request');
}
}
async rejectJoinRequest(leagueId: string, joinRequestId: string): Promise<Result<void, string>> {
async rejectJoinRequest(
leagueId: string,
joinRequestId: string,
): Promise<Result<void, string>> {
try {
await this.service.rejectJoinRequest(leagueId, joinRequestId);
const result = await this.service.rejectJoinRequest(leagueId, joinRequestId);
if (result.isErr()) {
return Result.err('Failed to reject join request');
}
return Result.ok(undefined);
} catch (error) {
console.error('rejectJoinRequest failed:', error);
return Result.err('Failed to reject join request');
}
}
async updateMemberRole(leagueId: string, driverId: string, role: MembershipRole): Promise<Result<void, string>> {
async updateMemberRole(
leagueId: string,
driverId: string,
role: MembershipRole,
): Promise<Result<void, string>> {
try {
await this.service.updateMemberRole(leagueId, driverId, role);
const result = await this.service.updateMemberRole(leagueId, driverId, role);
if (result.isErr()) {
return Result.err('Failed to update member role');
}
return Result.ok(undefined);
} catch (error) {
console.error('updateMemberRole failed:', error);
return Result.err('Failed to update member role');
}
}
async removeMember(leagueId: string, driverId: string): Promise<Result<void, string>> {
async removeMember(
leagueId: string,
driverId: string,
): Promise<Result<void, string>> {
try {
await this.service.removeMember(leagueId, driverId);
const result = await this.service.removeMember(leagueId, driverId);
// LeagueService.removeMember returns any, but we expect success: boolean based on implementation
if (result && typeof result === 'object' && 'success' in result && (result as { success: boolean }).success === false) {
return Result.err('Failed to remove member');
}
// If it's a Result object (some methods return Result, some return any)
if (result && typeof result === 'object' && 'isErr' in result && typeof (result as { isErr: () => boolean }).isErr === 'function' && (result as { isErr: () => boolean }).isErr()) {
return Result.err('Failed to remove member');
}
return Result.ok(undefined);
} catch (error) {
console.error('removeMember failed:', error);
return Result.err('Failed to remove member');
}
}
}
}