website refactor
This commit is contained in:
36
apps/website/lib/page-queries/TeamLeaderboardPageQuery.ts
Normal file
36
apps/website/lib/page-queries/TeamLeaderboardPageQuery.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { PresentationError, mapToPresentationError } from '@/lib/contracts/page-queries/PresentationError';
|
||||
import { TeamService } from '@/lib/services/teams/TeamService';
|
||||
import type { TeamSummaryViewModel } from '@/lib/view-models/TeamSummaryViewModel';
|
||||
|
||||
export interface TeamLeaderboardPageData {
|
||||
teams: TeamSummaryViewModel[];
|
||||
}
|
||||
|
||||
export class TeamLeaderboardPageQuery implements PageQuery<TeamLeaderboardPageData, void> {
|
||||
async execute(): Promise<Result<TeamLeaderboardPageData, PresentationError>> {
|
||||
try {
|
||||
const service = new TeamService();
|
||||
const result = await service.getAllTeams();
|
||||
|
||||
if (result.isErr()) {
|
||||
return Result.err(mapToPresentationError(result.getError()));
|
||||
}
|
||||
|
||||
const teams = result.unwrap().map(t => ({
|
||||
id: t.id,
|
||||
name: t.name,
|
||||
logoUrl: t.logoUrl,
|
||||
memberCount: t.memberCount,
|
||||
totalWins: t.totalWins,
|
||||
totalRaces: t.totalRaces,
|
||||
rating: 1450, // Mocked as in original
|
||||
} as TeamSummaryViewModel));
|
||||
|
||||
return Result.ok({ teams });
|
||||
} catch (error) {
|
||||
return Result.err('unknown');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user