view data fixes
This commit is contained in:
@@ -1,75 +1,101 @@
|
||||
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 { Mutation } from '@/lib/contracts/mutations/Mutation';
|
||||
|
||||
/**
|
||||
* ScheduleAdminMutation
|
||||
*
|
||||
* Framework-agnostic mutation for schedule administration operations.
|
||||
* Can be called from Server Actions or other contexts.
|
||||
*/
|
||||
export class ScheduleAdminMutation {
|
||||
private service: LeagueService;
|
||||
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() {
|
||||
// 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 publishSchedule(leagueId: string, seasonId: string): Promise<Result<void, string>> {
|
||||
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 {
|
||||
await this.service.publishAdminSchedule(leagueId, seasonId);
|
||||
const result = await this.service.publishAdminSchedule(leagueId, seasonId);
|
||||
if (result.isErr()) {
|
||||
return Result.err('Failed to publish schedule');
|
||||
}
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
console.error('publishSchedule failed:', error);
|
||||
return Result.err('Failed to publish schedule');
|
||||
}
|
||||
}
|
||||
|
||||
async unpublishSchedule(leagueId: string, seasonId: string): Promise<Result<void, string>> {
|
||||
async unpublishSchedule(
|
||||
leagueId: string,
|
||||
seasonId: string,
|
||||
): Promise<Result<void, string>> {
|
||||
try {
|
||||
await this.service.unpublishAdminSchedule(leagueId, seasonId);
|
||||
const result = await this.service.unpublishAdminSchedule(leagueId, seasonId);
|
||||
if (result.isErr()) {
|
||||
return Result.err('Failed to unpublish schedule');
|
||||
}
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
console.error('unpublishSchedule failed:', 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>> {
|
||||
async createRace(
|
||||
leagueId: string,
|
||||
seasonId: string,
|
||||
input: { track: string; car: string; scheduledAtIso: string },
|
||||
): Promise<Result<void, string>> {
|
||||
try {
|
||||
await this.service.createAdminScheduleRace(leagueId, seasonId, input);
|
||||
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) {
|
||||
console.error('createRace failed:', 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>> {
|
||||
async updateRace(
|
||||
leagueId: string,
|
||||
seasonId: string,
|
||||
raceId: string,
|
||||
input: Partial<{ track: string; car: string; scheduledAtIso: string }>,
|
||||
): Promise<Result<void, string>> {
|
||||
try {
|
||||
await this.service.updateAdminScheduleRace(leagueId, seasonId, raceId, input);
|
||||
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) {
|
||||
console.error('updateRace failed:', error);
|
||||
return Result.err('Failed to update race');
|
||||
}
|
||||
}
|
||||
|
||||
async deleteRace(leagueId: string, seasonId: string, raceId: string): Promise<Result<void, string>> {
|
||||
async deleteRace(
|
||||
leagueId: string,
|
||||
seasonId: string,
|
||||
raceId: string,
|
||||
): Promise<Result<void, string>> {
|
||||
try {
|
||||
await this.service.deleteAdminScheduleRace(leagueId, seasonId, raceId);
|
||||
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) {
|
||||
console.error('deleteRace failed:', error);
|
||||
return Result.err('Failed to delete race');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user