api client refactor
This commit is contained in:
39
apps/website/lib/view-models/LeagueMemberViewModel.ts
Normal file
39
apps/website/lib/view-models/LeagueMemberViewModel.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { LeagueMemberDto, DriverDto } from '../dtos';
|
||||
|
||||
export class LeagueMemberViewModel implements LeagueMemberDto {
|
||||
driverId: string;
|
||||
driver?: DriverDto;
|
||||
role: string;
|
||||
joinedAt: string;
|
||||
|
||||
private currentUserId: string;
|
||||
|
||||
constructor(dto: LeagueMemberDto, currentUserId: string) {
|
||||
Object.assign(this, dto);
|
||||
this.currentUserId = currentUserId;
|
||||
}
|
||||
|
||||
/** UI-specific: Formatted join date */
|
||||
get formattedJoinedAt(): string {
|
||||
return new Date(this.joinedAt).toLocaleDateString();
|
||||
}
|
||||
|
||||
/** UI-specific: Badge variant for role */
|
||||
get roleBadgeVariant(): string {
|
||||
switch (this.role) {
|
||||
case 'owner': return 'primary';
|
||||
case 'admin': return 'secondary';
|
||||
default: return 'default';
|
||||
}
|
||||
}
|
||||
|
||||
/** UI-specific: Whether this member is the owner */
|
||||
get isOwner(): boolean {
|
||||
return this.role === 'owner';
|
||||
}
|
||||
|
||||
/** UI-specific: Whether this is the current user */
|
||||
get isCurrentUser(): boolean {
|
||||
return this.driverId === this.currentUserId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user