37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
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: any) => ({
|
|
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');
|
|
}
|
|
}
|
|
}
|