api client refactor
This commit is contained in:
37
apps/website/lib/view-models/UserProfileViewModel.ts
Normal file
37
apps/website/lib/view-models/UserProfileViewModel.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user