view data fixes
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 5m54s
Contract Testing / contract-snapshot (pull_request) Has been skipped

This commit is contained in:
2026-01-23 13:04:05 +01:00
parent d97f50ed72
commit e22033be38
24 changed files with 605 additions and 455 deletions

View File

@@ -2,9 +2,15 @@
* Driver view model
* UI representation of a driver
*
* Note: No matching generated DTO available yet
* 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;
};
export class DriverViewModel extends ViewModel {
id: string;
@@ -16,25 +22,16 @@ export class DriverViewModel extends ViewModel {
bio?: string;
joinedAt?: string;
constructor(dto: {
id: string;
name: string;
avatarUrl?: string | null;
iracingId?: string;
rating?: number;
country?: string;
bio?: string;
joinedAt?: string;
}) {
constructor(viewData: DriverViewModelViewData) {
super();
this.id = dto.id;
this.name = dto.name;
this.avatarUrl = dto.avatarUrl ?? null;
if (dto.iracingId !== undefined) this.iracingId = dto.iracingId;
if (dto.rating !== undefined) this.rating = dto.rating;
if (dto.country !== undefined) this.country = dto.country;
if (dto.bio !== undefined) this.bio = dto.bio;
if (dto.joinedAt !== undefined) this.joinedAt = dto.joinedAt;
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;
}
/** UI-specific: Whether driver has an iRacing ID */
@@ -44,6 +41,6 @@ export class DriverViewModel extends ViewModel {
/** UI-specific: Formatted rating */
get formattedRating(): string {
return this.rating ? this.rating.toFixed(0) : 'Unrated';
return this.rating ? this.rating.toFixed(0) : "Unrated";
}
}