Files
gridpilot.gg/apps/website/lib/view-models/DriverViewModel.ts
Marc Mintel d97f50ed72
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 6m4s
Contract Testing / contract-snapshot (pull_request) Has been skipped
view data fixes
2026-01-23 11:59:49 +01:00

49 lines
1.2 KiB
TypeScript

/**
* Driver view model
* UI representation of a driver
*
* Note: No matching generated DTO available yet
*/
import { ViewModel } from "../contracts/view-models/ViewModel";
export class DriverViewModel extends ViewModel {
id: string;
name: string;
avatarUrl: string | null;
iracingId?: string;
rating?: number;
country?: string;
bio?: string;
joinedAt?: string;
constructor(dto: {
id: string;
name: string;
avatarUrl?: string | null;
iracingId?: string;
rating?: number;
country?: string;
bio?: string;
joinedAt?: string;
}) {
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;
}
/** UI-specific: Whether driver has an iRacing ID */
get hasIracingId(): boolean {
return !!this.iracingId;
}
/** UI-specific: Formatted rating */
get formattedRating(): string {
return this.rating ? this.rating.toFixed(0) : 'Unrated';
}
}