view data fixes
This commit is contained in:
@@ -1,31 +1,44 @@
|
||||
import type { GetDriverTeamOutputDTO } from '@/lib/types/generated/GetDriverTeamOutputDTO';
|
||||
|
||||
/**
|
||||
* View Model for Driver's Team
|
||||
*
|
||||
* Represents a driver's team membership in a UI-ready format.
|
||||
* Client-only UI helper built from ViewData.
|
||||
*/
|
||||
|
||||
import { ProfileDisplay } from "../display-objects/ProfileDisplay";
|
||||
import { ViewModel } from "../contracts/view-models/ViewModel";
|
||||
import type { TeamDetailData } from "../view-data/TeamDetailViewData";
|
||||
|
||||
export class DriverTeamViewModel extends ViewModel {
|
||||
teamId: string;
|
||||
teamName: string;
|
||||
tag: string;
|
||||
role: string;
|
||||
isOwner: boolean;
|
||||
canManage: boolean;
|
||||
constructor(private readonly viewData: TeamDetailData) {
|
||||
super();
|
||||
}
|
||||
|
||||
constructor(dto: GetDriverTeamOutputDTO) {
|
||||
this.teamId = dto.team.id;
|
||||
this.teamName = dto.team.name;
|
||||
this.tag = dto.team.tag;
|
||||
this.role = dto.membership.role;
|
||||
this.isOwner = dto.isOwner;
|
||||
this.canManage = dto.canManage;
|
||||
get teamId(): string {
|
||||
return this.viewData.id;
|
||||
}
|
||||
|
||||
get teamName(): string {
|
||||
return this.viewData.name;
|
||||
}
|
||||
|
||||
get tag(): string {
|
||||
return this.viewData.tag;
|
||||
}
|
||||
|
||||
get role(): string {
|
||||
return this.viewData.membership?.role ?? "member";
|
||||
}
|
||||
|
||||
get canManage(): boolean {
|
||||
return this.viewData.canManage;
|
||||
}
|
||||
|
||||
get isOwner(): boolean {
|
||||
return this.viewData.membership?.role === "owner";
|
||||
}
|
||||
|
||||
/** UI-specific: Display role */
|
||||
get displayRole(): string {
|
||||
return this.role.charAt(0).toUpperCase() + this.role.slice(1);
|
||||
return ProfileDisplay.getTeamRole(this.role).text;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user