Files
gridpilot.gg/apps/website/lib/page-queries/LeagueSchedulePageQuery.ts
2026-01-16 01:00:03 +01:00

26 lines
1.2 KiB
TypeScript

import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
import { Result } from '@/lib/contracts/Result';
import { LeagueScheduleService } from '@/lib/services/leagues/LeagueScheduleService';
import { LeagueScheduleViewDataBuilder } from '@/lib/builders/view-data/LeagueScheduleViewDataBuilder';
import { LeagueScheduleViewData } from '@/lib/view-data/leagues/LeagueScheduleViewData';
import { type PresentationError, mapToPresentationError } from '@/lib/contracts/page-queries/PresentationError';
export class LeagueSchedulePageQuery implements PageQuery<LeagueScheduleViewData, string, PresentationError> {
async execute(leagueId: string): Promise<Result<LeagueScheduleViewData, PresentationError>> {
const service = new LeagueScheduleService();
const result = await service.getScheduleData(leagueId);
if (result.isErr()) {
return Result.err(mapToPresentationError(result.getError()));
}
const viewData = LeagueScheduleViewDataBuilder.build(result.unwrap());
return Result.ok(viewData);
}
static async execute(leagueId: string): Promise<Result<LeagueScheduleViewData, PresentationError>> {
const query = new LeagueSchedulePageQuery();
return query.execute(leagueId);
}
}