37 lines
941 B
TypeScript
37 lines
941 B
TypeScript
import { DriverDto } from '../dtos';
|
|
|
|
export class UserProfileViewModel implements DriverDto {
|
|
id: string;
|
|
name: string;
|
|
avatarUrl?: string;
|
|
iracingId?: string;
|
|
rating?: number;
|
|
|
|
constructor(dto: DriverDto) {
|
|
Object.assign(this, dto);
|
|
}
|
|
|
|
/** UI-specific: Formatted rating */
|
|
get formattedRating(): string {
|
|
return this.rating ? this.rating.toFixed(0) : 'Unrated';
|
|
}
|
|
|
|
/** UI-specific: Whether has iRacing ID */
|
|
get hasIracingId(): boolean {
|
|
return !!this.iracingId;
|
|
}
|
|
|
|
/** UI-specific: Profile completeness percentage */
|
|
get profileCompleteness(): number {
|
|
let complete = 1; // id always there
|
|
if (this.avatarUrl) complete++;
|
|
if (this.iracingId) complete++;
|
|
if (this.rating) complete++;
|
|
return Math.round((complete / 4) * 100);
|
|
}
|
|
|
|
/** UI-specific: Avatar initials */
|
|
get avatarInitials(): string {
|
|
return this.name.split(' ').map(n => n[0]).join('').toUpperCase();
|
|
}
|
|
} |