Files
gridpilot.gg/apps/website/lib/view-models/TeamDetailsViewModel.ts
Marc Mintel d97f50ed72
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 6m4s
Contract Testing / contract-snapshot (pull_request) Has been skipped
view data fixes
2026-01-23 11:59:49 +01:00

69 lines
2.0 KiB
TypeScript

import type { GetTeamDetailsOutputDTO } from '@/lib/types/generated/GetTeamDetailsOutputDTO';
import { ViewModel } from "../contracts/view-models/ViewModel";
export class TeamDetailsViewModel extends ViewModel {
id!: string;
name!: string;
tag!: string;
description?: string;
ownerId!: string;
leagues!: string[];
createdAt: string | undefined;
specialization: string | undefined;
region: string | undefined;
languages: string[] | undefined;
category: string | undefined;
membership: { role: string; joinedAt: string; isActive: boolean } | null;
private _canManage: boolean;
private currentUserId: string;
constructor(dto: GetTeamDetailsOutputDTO, currentUserId: string) {
this.id = dto.team.id;
this.name = dto.team.name;
this.tag = dto.team.tag;
this.description = dto.team.description;
this.ownerId = dto.team.ownerId;
this.leagues = dto.team.leagues;
this.createdAt = dto.team.createdAt;
const teamExtras = dto.team as typeof dto.team & {
specialization?: string;
region?: string;
languages?: string[];
category?: string;
};
this.specialization = teamExtras.specialization ?? undefined;
this.region = teamExtras.region ?? undefined;
this.languages = teamExtras.languages ?? undefined;
this.category = teamExtras.category ?? undefined;
this.membership = dto.membership ? {
role: dto.membership.role,
joinedAt: dto.membership.joinedAt,
isActive: dto.membership.isActive
} : null;
this._canManage = dto.canManage;
this.currentUserId = currentUserId;
}
/** UI-specific: Whether current user is owner */
get isOwner(): boolean {
return this.membership?.role === 'owner';
}
/** UI-specific: Whether can manage team */
get canManage(): boolean {
return this._canManage;
}
/** UI-specific: Whether current user is member */
get isMember(): boolean {
return this.membership !== null;
}
/** UI-specific: Current user's role */
get userRole(): string {
return this.membership?.role || 'none';
}
}