api client refactor
This commit is contained in:
36
apps/website/lib/view-models/SessionViewModel.ts
Normal file
36
apps/website/lib/view-models/SessionViewModel.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { SessionDataDto } from '../dtos';
|
||||
|
||||
export class SessionViewModel implements SessionDataDto {
|
||||
userId: string;
|
||||
email: string;
|
||||
displayName?: string;
|
||||
driverId?: string;
|
||||
isAuthenticated: boolean;
|
||||
|
||||
constructor(dto: SessionDataDto) {
|
||||
Object.assign(this, dto);
|
||||
}
|
||||
|
||||
/** UI-specific: User greeting */
|
||||
get greeting(): string {
|
||||
return `Hello, ${this.displayName || this.email}!`;
|
||||
}
|
||||
|
||||
/** UI-specific: Avatar initials */
|
||||
get avatarInitials(): string {
|
||||
if (this.displayName) {
|
||||
return this.displayName.split(' ').map(n => n[0]).join('').toUpperCase();
|
||||
}
|
||||
return this.email[0].toUpperCase();
|
||||
}
|
||||
|
||||
/** UI-specific: Whether has driver profile */
|
||||
get hasDriverProfile(): boolean {
|
||||
return !!this.driverId;
|
||||
}
|
||||
|
||||
/** UI-specific: Authentication status display */
|
||||
get authStatusDisplay(): string {
|
||||
return this.isAuthenticated ? 'Logged In' : 'Logged Out';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user