102 lines
2.9 KiB
TypeScript
102 lines
2.9 KiB
TypeScript
import { Result } from '@/lib/contracts/Result';
|
|
import { LeagueService } from '@/lib/services/leagues/LeagueService';
|
|
import type { Mutation } from '@/lib/contracts/mutations/Mutation';
|
|
|
|
export interface ScheduleAdminCommand {
|
|
leagueId: string;
|
|
seasonId: string;
|
|
raceId?: string;
|
|
input?: { track: string; car: string; scheduledAtIso: string };
|
|
}
|
|
|
|
export class ScheduleAdminMutation implements Mutation<ScheduleAdminCommand, void, string> {
|
|
private readonly service: LeagueService;
|
|
|
|
constructor() {
|
|
this.service = new LeagueService();
|
|
}
|
|
|
|
async execute(_command: ScheduleAdminCommand): Promise<Result<void, string>> {
|
|
return Result.err('Use specific methods');
|
|
}
|
|
|
|
async publishSchedule(
|
|
leagueId: string,
|
|
seasonId: string,
|
|
): Promise<Result<void, string>> {
|
|
try {
|
|
const result = await this.service.publishAdminSchedule(leagueId, seasonId);
|
|
if (result.isErr()) {
|
|
return Result.err('Failed to publish schedule');
|
|
}
|
|
return Result.ok(undefined);
|
|
} catch (error) {
|
|
return Result.err('Failed to publish schedule');
|
|
}
|
|
}
|
|
|
|
async unpublishSchedule(
|
|
leagueId: string,
|
|
seasonId: string,
|
|
): Promise<Result<void, string>> {
|
|
try {
|
|
const result = await this.service.unpublishAdminSchedule(leagueId, seasonId);
|
|
if (result.isErr()) {
|
|
return Result.err('Failed to unpublish schedule');
|
|
}
|
|
return Result.ok(undefined);
|
|
} catch (error) {
|
|
return Result.err('Failed to unpublish schedule');
|
|
}
|
|
}
|
|
|
|
async createRace(
|
|
leagueId: string,
|
|
seasonId: string,
|
|
input: { track: string; car: string; scheduledAtIso: string },
|
|
): Promise<Result<void, string>> {
|
|
try {
|
|
const result = await this.service.createAdminScheduleRace(leagueId, seasonId, input);
|
|
if (result.isErr()) {
|
|
return Result.err('Failed to create race');
|
|
}
|
|
return Result.ok(undefined);
|
|
} catch (error) {
|
|
return Result.err('Failed to create race');
|
|
}
|
|
}
|
|
|
|
async updateRace(
|
|
leagueId: string,
|
|
seasonId: string,
|
|
raceId: string,
|
|
input: Partial<{ track: string; car: string; scheduledAtIso: string }>,
|
|
): Promise<Result<void, string>> {
|
|
try {
|
|
const result = await this.service.updateAdminScheduleRace(leagueId, seasonId, raceId, input);
|
|
if (result.isErr()) {
|
|
return Result.err('Failed to update race');
|
|
}
|
|
return Result.ok(undefined);
|
|
} catch (error) {
|
|
return Result.err('Failed to update race');
|
|
}
|
|
}
|
|
|
|
async deleteRace(
|
|
leagueId: string,
|
|
seasonId: string,
|
|
raceId: string,
|
|
): Promise<Result<void, string>> {
|
|
try {
|
|
const result = await this.service.deleteAdminScheduleRace(leagueId, seasonId, raceId);
|
|
if (result.isErr()) {
|
|
return Result.err('Failed to delete race');
|
|
}
|
|
return Result.ok(undefined);
|
|
} catch (error) {
|
|
return Result.err('Failed to delete race');
|
|
}
|
|
}
|
|
}
|