90 lines
2.9 KiB
TypeScript
90 lines
2.9 KiB
TypeScript
import { Result } from '@/lib/contracts/Result';
|
|
import { LeagueService } from '@/lib/services/leagues/LeagueService';
|
|
import type { MembershipRole } from '@/lib/types/MembershipRole';
|
|
import type { Mutation } from '@/lib/contracts/mutations/Mutation';
|
|
|
|
export interface RosterAdminCommand {
|
|
leagueId: string;
|
|
driverId?: string;
|
|
joinRequestId?: string;
|
|
role?: MembershipRole;
|
|
}
|
|
|
|
export class RosterAdminMutation implements Mutation<RosterAdminCommand, void, string> {
|
|
private readonly service: LeagueService;
|
|
|
|
constructor() {
|
|
this.service = new LeagueService();
|
|
}
|
|
|
|
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 {
|
|
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) {
|
|
return Result.err('Failed to approve join request');
|
|
}
|
|
}
|
|
|
|
async rejectJoinRequest(
|
|
leagueId: string,
|
|
joinRequestId: string,
|
|
): Promise<Result<void, string>> {
|
|
try {
|
|
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) {
|
|
return Result.err('Failed to reject join request');
|
|
}
|
|
}
|
|
|
|
async updateMemberRole(
|
|
leagueId: string,
|
|
driverId: string,
|
|
role: MembershipRole,
|
|
): Promise<Result<void, string>> {
|
|
try {
|
|
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) {
|
|
return Result.err('Failed to update member role');
|
|
}
|
|
}
|
|
|
|
async removeMember(
|
|
leagueId: string,
|
|
driverId: string,
|
|
): Promise<Result<void, string>> {
|
|
try {
|
|
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) {
|
|
return Result.err('Failed to remove member');
|
|
}
|
|
}
|
|
}
|