resolve manual DTOs
This commit is contained in:
@@ -1,70 +1,53 @@
|
||||
import { TeamMemberViewModel } from './TeamMemberViewModel';
|
||||
|
||||
// Note: No generated DTO available for TeamDetails yet
|
||||
interface DriverDTO {
|
||||
id: string;
|
||||
name: string;
|
||||
avatarUrl?: string;
|
||||
iracingId?: string;
|
||||
rating?: number;
|
||||
}
|
||||
interface TeamMemberDTO {
|
||||
driverId: string;
|
||||
driver?: DriverDTO;
|
||||
role: string;
|
||||
joinedAt: string;
|
||||
}
|
||||
interface TeamDetailsDTO {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
logoUrl?: string;
|
||||
memberCount: number;
|
||||
ownerId: string;
|
||||
members: TeamMemberDTO[];
|
||||
}
|
||||
import type { GetTeamDetailsOutputDTO } from '@/lib/types/generated/GetTeamDetailsOutputDTO';
|
||||
|
||||
export class TeamDetailsViewModel {
|
||||
id: string;
|
||||
name: string;
|
||||
tag: string;
|
||||
description?: string;
|
||||
logoUrl?: string;
|
||||
memberCount: number;
|
||||
ownerId: string;
|
||||
members: TeamMemberViewModel[];
|
||||
|
||||
leagues: string[];
|
||||
createdAt?: string;
|
||||
specialization?: string;
|
||||
region?: string;
|
||||
languages?: string[];
|
||||
membership: { role: string; joinedAt: string; isActive: boolean } | null;
|
||||
canManage: boolean;
|
||||
private currentUserId: string;
|
||||
|
||||
constructor(dto: TeamDetailsDTO, currentUserId: string) {
|
||||
this.id = dto.id;
|
||||
this.name = dto.name;
|
||||
this.description = dto.description;
|
||||
this.logoUrl = dto.logoUrl;
|
||||
this.memberCount = dto.memberCount;
|
||||
this.ownerId = dto.ownerId;
|
||||
this.members = dto.members.map(m => new TeamMemberViewModel(m, currentUserId, dto.ownerId));
|
||||
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;
|
||||
this.specialization = dto.team.specialization;
|
||||
this.region = dto.team.region;
|
||||
this.languages = dto.team.languages;
|
||||
this.membership = dto.membership;
|
||||
this.canManage = dto.canManage;
|
||||
this.currentUserId = currentUserId;
|
||||
}
|
||||
|
||||
/** UI-specific: Whether current user is owner */
|
||||
get isOwner(): boolean {
|
||||
return this.currentUserId === this.ownerId;
|
||||
return this.membership?.role === 'owner';
|
||||
}
|
||||
|
||||
/** UI-specific: Whether can add members */
|
||||
get canAddMembers(): boolean {
|
||||
return this.isOwner && this.memberCount < 10; // Assuming max 10
|
||||
/** UI-specific: Whether can manage team */
|
||||
get canManage(): boolean {
|
||||
return this.canManage;
|
||||
}
|
||||
|
||||
/** UI-specific: Member management actions available */
|
||||
get memberActionsAvailable(): boolean {
|
||||
return this.isOwner;
|
||||
/** UI-specific: Whether current user is member */
|
||||
get isMember(): boolean {
|
||||
return this.membership !== null;
|
||||
}
|
||||
|
||||
/** UI-specific: Team status */
|
||||
get teamStatus(): string {
|
||||
if (this.memberCount < 5) return 'Recruiting';
|
||||
if (this.memberCount < 10) return 'Active';
|
||||
return 'Full';
|
||||
/** UI-specific: Current user's role */
|
||||
get userRole(): string {
|
||||
return this.membership?.role || 'none';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user