Files
gridpilot.gg/apps/website/lib/view-models/TeamDetailsViewModel.ts
2025-12-26 11:49:20 +01:00

64 lines
1.8 KiB
TypeScript

import type { GetTeamDetailsOutputDTO } from '@/lib/types/generated/GetTeamDetailsOutputDTO';
export class TeamDetailsViewModel {
id!: string;
name!: string;
tag!: string;
description?: string;
ownerId!: string;
leagues!: string[];
createdAt: string | undefined;
specialization: string | undefined;
region: string | undefined;
languages: 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[];
};
this.specialization = teamExtras.specialization ?? undefined;
this.region = teamExtras.region ?? undefined;
this.languages = teamExtras.languages ?? 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';
}
}