view data fixes
This commit is contained in:
@@ -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";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user