wip
This commit is contained in:
@@ -3,12 +3,36 @@ import type {
|
||||
TeamsLeaderboardViewModel,
|
||||
TeamLeaderboardItemViewModel,
|
||||
SkillLevel,
|
||||
TeamsLeaderboardResultDTO,
|
||||
} from '@gridpilot/racing/application/presenters/ITeamsLeaderboardPresenter';
|
||||
|
||||
interface TeamLeaderboardInput {
|
||||
id: string;
|
||||
name: string;
|
||||
memberCount: number;
|
||||
rating: number | null;
|
||||
totalWins: number;
|
||||
totalRaces: number;
|
||||
performanceLevel: SkillLevel;
|
||||
isRecruiting: boolean;
|
||||
createdAt: Date;
|
||||
description?: string | null;
|
||||
specialization?: string | null;
|
||||
region?: string | null;
|
||||
languages?: string[];
|
||||
}
|
||||
|
||||
export class TeamsLeaderboardPresenter implements ITeamsLeaderboardPresenter {
|
||||
private viewModel: TeamsLeaderboardViewModel | null = null;
|
||||
|
||||
present(teams: any[], recruitingCount: number): void {
|
||||
reset(): void {
|
||||
this.viewModel = null;
|
||||
}
|
||||
|
||||
present(input: TeamsLeaderboardResultDTO): void {
|
||||
const teams = (input.teams ?? []) as TeamLeaderboardInput[];
|
||||
const recruitingCount = input.recruitingCount ?? 0;
|
||||
|
||||
const transformedTeams = teams.map((team) => this.transformTeam(team));
|
||||
|
||||
const groupsBySkillLevel = transformedTeams.reduce<Record<SkillLevel, TeamLeaderboardItemViewModel[]>>(
|
||||
@@ -41,14 +65,22 @@ export class TeamsLeaderboardPresenter implements ITeamsLeaderboardPresenter {
|
||||
};
|
||||
}
|
||||
|
||||
getViewModel(): TeamsLeaderboardViewModel {
|
||||
if (!this.viewModel) {
|
||||
throw new Error('ViewModel not yet generated. Call present() first.');
|
||||
}
|
||||
getViewModel(): TeamsLeaderboardViewModel | null {
|
||||
return this.viewModel;
|
||||
}
|
||||
|
||||
private transformTeam(team: any): TeamLeaderboardItemViewModel {
|
||||
private transformTeam(team: TeamLeaderboardInput): TeamLeaderboardItemViewModel {
|
||||
let specialization: TeamLeaderboardItemViewModel['specialization'];
|
||||
if (
|
||||
team.specialization === 'endurance' ||
|
||||
team.specialization === 'sprint' ||
|
||||
team.specialization === 'mixed'
|
||||
) {
|
||||
specialization = team.specialization;
|
||||
} else {
|
||||
specialization = undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
id: team.id,
|
||||
name: team.name,
|
||||
@@ -56,13 +88,13 @@ export class TeamsLeaderboardPresenter implements ITeamsLeaderboardPresenter {
|
||||
rating: team.rating,
|
||||
totalWins: team.totalWins,
|
||||
totalRaces: team.totalRaces,
|
||||
performanceLevel: team.performanceLevel as SkillLevel,
|
||||
performanceLevel: team.performanceLevel,
|
||||
isRecruiting: team.isRecruiting,
|
||||
createdAt: team.createdAt,
|
||||
description: team.description,
|
||||
specialization: team.specialization,
|
||||
region: team.region,
|
||||
languages: team.languages,
|
||||
description: team.description ?? '',
|
||||
specialization: specialization ?? 'mixed',
|
||||
region: team.region ?? '',
|
||||
languages: team.languages ?? [],
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user