view data fixes
This commit is contained in:
@@ -5,35 +5,26 @@
|
||||
* Note: client-only ViewModel created from ViewData (never DTO).
|
||||
*/
|
||||
import { ViewModel } from "../contracts/view-models/ViewModel";
|
||||
import type { DriverData } from "../view-data/LeagueStandingsViewData";
|
||||
|
||||
type DriverViewModelViewData = DriverData & {
|
||||
bio?: string;
|
||||
joinedAt?: string;
|
||||
};
|
||||
import { RatingDisplay } from "../display-objects/RatingDisplay";
|
||||
import type { DriverViewData } from "../view-data/DriverViewData";
|
||||
|
||||
export class DriverViewModel extends ViewModel {
|
||||
id: string;
|
||||
name: string;
|
||||
avatarUrl: string | null;
|
||||
iracingId?: string;
|
||||
rating?: number;
|
||||
country?: string;
|
||||
bio?: string;
|
||||
joinedAt?: string;
|
||||
private readonly data: DriverViewData;
|
||||
|
||||
constructor(viewData: DriverViewModelViewData) {
|
||||
constructor(data: DriverViewData) {
|
||||
super();
|
||||
this.id = viewData.id;
|
||||
this.name = viewData.name;
|
||||
this.avatarUrl = viewData.avatarUrl ?? null;
|
||||
if (viewData.iracingId !== undefined) this.iracingId = viewData.iracingId;
|
||||
if (viewData.rating !== undefined) this.rating = viewData.rating;
|
||||
if (viewData.country !== undefined) this.country = viewData.country;
|
||||
if (viewData.bio !== undefined) this.bio = viewData.bio;
|
||||
if (viewData.joinedAt !== undefined) this.joinedAt = viewData.joinedAt;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
get id(): string { return this.data.id; }
|
||||
get name(): string { return this.data.name; }
|
||||
get avatarUrl(): string { return this.data.avatarUrl || ''; }
|
||||
get iracingId(): string | undefined { return this.data.iracingId; }
|
||||
get rating(): number | undefined { return this.data.rating; }
|
||||
get country(): string | undefined { return this.data.country; }
|
||||
get bio(): string | undefined { return this.data.bio; }
|
||||
get joinedAt(): string | undefined { return this.data.joinedAt; }
|
||||
|
||||
/** UI-specific: Whether driver has an iRacing ID */
|
||||
get hasIracingId(): boolean {
|
||||
return !!this.iracingId;
|
||||
@@ -41,6 +32,6 @@ export class DriverViewModel extends ViewModel {
|
||||
|
||||
/** UI-specific: Formatted rating */
|
||||
get formattedRating(): string {
|
||||
return this.rating ? this.rating.toFixed(0) : "Unrated";
|
||||
return this.rating !== undefined ? RatingDisplay.format(this.rating) : "Unrated";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user