38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import type { Team } from '@gridpilot/racing/domain/entities/Team';
|
|
import type {
|
|
IAllTeamsPresenter,
|
|
TeamListItemViewModel,
|
|
AllTeamsViewModel,
|
|
} from '@gridpilot/racing/application/presenters/IAllTeamsPresenter';
|
|
|
|
export class AllTeamsPresenter implements IAllTeamsPresenter {
|
|
private viewModel: AllTeamsViewModel | null = null;
|
|
|
|
present(teams: Array<Team & { memberCount?: number }>): AllTeamsViewModel {
|
|
const teamItems: TeamListItemViewModel[] = teams.map((team) => ({
|
|
id: team.id,
|
|
name: team.name,
|
|
tag: team.tag,
|
|
description: team.description,
|
|
memberCount: team.memberCount ?? 0,
|
|
leagues: team.leagues,
|
|
specialization: team.specialization as 'endurance' | 'sprint' | 'mixed' | undefined,
|
|
region: team.region,
|
|
languages: team.languages,
|
|
}));
|
|
|
|
this.viewModel = {
|
|
teams: teamItems,
|
|
totalCount: teamItems.length,
|
|
};
|
|
|
|
return this.viewModel;
|
|
}
|
|
|
|
getViewModel(): AllTeamsViewModel {
|
|
if (!this.viewModel) {
|
|
throw new Error('Presenter has not been called yet');
|
|
}
|
|
return this.viewModel;
|
|
}
|
|
} |