view data fixes
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { DriverProfileDriverSummaryViewModel } from "./DriverProfileDriverSummaryViewModel";
|
||||
export type { DriverProfileDriverSummaryViewModel };
|
||||
import { ProfileViewData } from "../view-data/ProfileViewData";
|
||||
import { ViewModel } from "../contracts/view-models/ViewModel";
|
||||
|
||||
export interface DriverProfileStatsViewModel {
|
||||
export interface DriverProfileStatsViewModel extends ViewModel {
|
||||
totalRaces: number;
|
||||
wins: number;
|
||||
podiums: number;
|
||||
@@ -18,7 +19,7 @@ export interface DriverProfileStatsViewModel {
|
||||
overallRank: number | null;
|
||||
}
|
||||
|
||||
export interface DriverProfileFinishDistributionViewModel {
|
||||
export interface DriverProfileFinishDistributionViewModel extends ViewModel {
|
||||
totalRaces: number;
|
||||
wins: number;
|
||||
podiums: number;
|
||||
@@ -27,7 +28,7 @@ export interface DriverProfileFinishDistributionViewModel {
|
||||
other: number;
|
||||
}
|
||||
|
||||
export interface DriverProfileTeamMembershipViewModel {
|
||||
export interface DriverProfileTeamMembershipViewModel extends ViewModel {
|
||||
teamId: string;
|
||||
teamName: string;
|
||||
teamTag: string | null;
|
||||
@@ -36,14 +37,14 @@ export interface DriverProfileTeamMembershipViewModel {
|
||||
isCurrent: boolean;
|
||||
}
|
||||
|
||||
export interface DriverProfileSocialFriendSummaryViewModel {
|
||||
export interface DriverProfileSocialFriendSummaryViewModel extends ViewModel {
|
||||
id: string;
|
||||
name: string;
|
||||
country: string;
|
||||
avatarUrl: string;
|
||||
}
|
||||
|
||||
export interface DriverProfileSocialSummaryViewModel {
|
||||
export interface DriverProfileSocialSummaryViewModel extends ViewModel {
|
||||
friendsCount: number;
|
||||
friends: DriverProfileSocialFriendSummaryViewModel[];
|
||||
}
|
||||
@@ -52,7 +53,7 @@ export type DriverProfileSocialPlatform = 'twitter' | 'youtube' | 'twitch' | 'di
|
||||
|
||||
export type DriverProfileAchievementRarity = 'common' | 'rare' | 'epic' | 'legendary';
|
||||
|
||||
export interface DriverProfileAchievementViewModel {
|
||||
export interface DriverProfileAchievementViewModel extends ViewModel {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
@@ -61,13 +62,13 @@ export interface DriverProfileAchievementViewModel {
|
||||
earnedAt: string;
|
||||
}
|
||||
|
||||
export interface DriverProfileSocialHandleViewModel {
|
||||
export interface DriverProfileSocialHandleViewModel extends ViewModel {
|
||||
platform: DriverProfileSocialPlatform;
|
||||
handle: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
export interface DriverProfileExtendedProfileViewModel {
|
||||
export interface DriverProfileExtendedProfileViewModel extends ViewModel {
|
||||
socialHandles: DriverProfileSocialHandleViewModel[];
|
||||
achievements: DriverProfileAchievementViewModel[];
|
||||
racingStyle: string;
|
||||
@@ -92,39 +93,72 @@ export interface DriverProfileViewModelData {
|
||||
* Driver Profile View Model
|
||||
*
|
||||
* Represents a fully prepared UI state for driver profile display.
|
||||
* Transforms API DTOs into UI-ready data structures.
|
||||
* Transforms ViewData into UI-ready data structures.
|
||||
*/
|
||||
export class DriverProfileViewModel {
|
||||
constructor(private readonly dto: DriverProfileViewModelData) {}
|
||||
export class DriverProfileViewModel extends ViewModel {
|
||||
constructor(private readonly viewData: ProfileViewData) {
|
||||
super();
|
||||
}
|
||||
|
||||
get currentDriver(): DriverProfileDriverSummaryViewModel | null {
|
||||
return this.dto.currentDriver;
|
||||
if (!this.viewData.driver) return null;
|
||||
return new DriverProfileDriverSummaryViewModel(this.viewData);
|
||||
}
|
||||
|
||||
get stats(): DriverProfileStatsViewModel | null {
|
||||
return this.dto.stats;
|
||||
}
|
||||
|
||||
get finishDistribution(): DriverProfileFinishDistributionViewModel | null {
|
||||
return this.dto.finishDistribution;
|
||||
if (!this.viewData.stats) return null;
|
||||
return {
|
||||
totalRaces: 0,
|
||||
wins: 0,
|
||||
podiums: 0,
|
||||
dnfs: 0,
|
||||
avgFinish: null,
|
||||
bestFinish: null,
|
||||
worstFinish: null,
|
||||
finishRate: null,
|
||||
winRate: null,
|
||||
podiumRate: null,
|
||||
percentile: null,
|
||||
rating: null,
|
||||
consistency: null,
|
||||
overallRank: null,
|
||||
};
|
||||
}
|
||||
|
||||
get teamMemberships(): DriverProfileTeamMembershipViewModel[] {
|
||||
return this.dto.teamMemberships;
|
||||
}
|
||||
|
||||
get socialSummary(): DriverProfileSocialSummaryViewModel {
|
||||
return this.dto.socialSummary;
|
||||
return this.viewData.teamMemberships.map((m) => ({
|
||||
teamId: m.teamId,
|
||||
teamName: m.teamName,
|
||||
teamTag: m.teamTag,
|
||||
role: m.roleLabel,
|
||||
joinedAt: m.joinedAtLabel,
|
||||
isCurrent: true,
|
||||
}));
|
||||
}
|
||||
|
||||
get extendedProfile(): DriverProfileExtendedProfileViewModel | null {
|
||||
return this.dto.extendedProfile;
|
||||
if (!this.viewData.extendedProfile) return null;
|
||||
return {
|
||||
socialHandles: this.viewData.extendedProfile.socialHandles.map((h) => ({
|
||||
platform: h.platformLabel.toLowerCase() as any,
|
||||
handle: h.handle,
|
||||
url: h.url,
|
||||
})),
|
||||
achievements: this.viewData.extendedProfile.achievements.map((a) => ({
|
||||
id: a.id,
|
||||
title: a.title,
|
||||
description: a.description,
|
||||
icon: a.icon,
|
||||
rarity: a.rarityLabel.toLowerCase() as any,
|
||||
earnedAt: a.earnedAtLabel,
|
||||
})),
|
||||
racingStyle: this.viewData.extendedProfile.racingStyle,
|
||||
favoriteTrack: this.viewData.extendedProfile.favoriteTrack,
|
||||
favoriteCar: this.viewData.extendedProfile.favoriteCar,
|
||||
timezone: this.viewData.extendedProfile.timezone,
|
||||
availableHours: this.viewData.extendedProfile.availableHours,
|
||||
lookingForTeam: this.viewData.extendedProfile.lookingForTeamLabel === 'Yes',
|
||||
openToRequests: this.viewData.extendedProfile.openToRequestsLabel === 'Yes',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw DTO for serialization or further processing
|
||||
*/
|
||||
toDTO(): DriverProfileViewModelData {
|
||||
return this.dto;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user