Files
gridpilot.gg/apps/api/src/modules/team/presenters/AllTeamsPresenter.ts
2025-12-16 10:50:15 +01:00

34 lines
887 B
TypeScript

import { IAllTeamsPresenter, AllTeamsResultDTO, AllTeamsViewModel, TeamListItemViewModel } from '@gridpilot/racing/application/presenters/IAllTeamsPresenter';
export class AllTeamsPresenter implements IAllTeamsPresenter {
private result: AllTeamsViewModel | null = null;
reset() {
this.result = null;
}
present(dto: AllTeamsResultDTO) {
const teams: TeamListItemViewModel[] = dto.teams.map(team => ({
id: team.id,
name: team.name,
tag: team.tag,
description: team.description,
memberCount: team.memberCount,
leagues: team.leagues || [],
}));
this.result = {
teams,
totalCount: teams.length,
};
}
getViewModel(): AllTeamsViewModel | null {
return this.result;
}
get viewModel(): AllTeamsViewModel {
if (!this.result) throw new Error('Presenter not presented');
return this.result;
}
}