Files
gridpilot.gg/apps/website/lib/view-models/DriverViewModel.ts
2026-01-24 01:07:43 +01:00

37 lines
1.2 KiB
TypeScript

/**
* Driver view model
* UI representation of a driver
*
* Note: client-only ViewModel created from ViewData (never DTO).
*/
import { ViewModel } from "../contracts/view-models/ViewModel";
import { RatingFormatter } from "../formatters/RatingFormatter";
import type { DriverViewData } from "../view-data/DriverViewData";
export class DriverViewModel extends ViewModel {
private readonly data: DriverViewData;
constructor(data: DriverViewData) {
super();
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;
}
/** UI-specific: Formatted rating */
get formattedRating(): string {
return this.rating !== undefined ? RatingFormatter.format(this.rating) : "Unrated";
}
}