Files
gridpilot.gg/apps/website/lib/page-queries/DriversPageQuery.ts
Marc Mintel ae58839eb2
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 5m53s
Contract Testing / contract-snapshot (pull_request) Has been skipped
view data fixes
2026-01-22 23:44:26 +01:00

46 lines
1.3 KiB
TypeScript

import { DriversViewDataBuilder } from '@/lib/builders/view-data/DriversViewDataBuilder';
import { Result } from '@/lib/contracts/Result';
import { DriversPageService } from '@/lib/services/drivers/DriversPageService';
import type { DriversViewData } from '@/lib/view-data/DriversViewData';
/**
* DriversPageQuery
*
* Server-side data fetcher for the drivers listing page.
* Returns Result<ViewData, PresentationError>
* Uses Service for data access and ViewDataBuilder for transformation.
*/
export class DriversPageQuery {
/**
* Execute the drivers page query
*
* @returns Result with ViewData or error
*/
static async execute(): Promise<Result<DriversViewData, string>> {
try {
// Manual wiring: construct dependencies explicitly
const service = new DriversPageService();
const result = await service.getLeaderboard();
if (result.isErr()) {
const error = result.getError();
if (error === 'notFound') {
return Result.err('NotFound');
}
return Result.err('Error');
}
// Build ViewData from DTO
const dto = result.unwrap();
const viewData = DriversViewDataBuilder.build(dto);
return Result.ok(viewData);
} catch (error) {
console.error('DriversPageQuery failed:', error);
return Result.err('Error');
}
}
}