60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import { AuthenticatedUserDTO } from '../types/generated/AuthenticatedUserDTO';
|
|
|
|
export class SessionViewModel {
|
|
userId: string;
|
|
email: string;
|
|
displayName: string;
|
|
|
|
constructor(dto: AuthenticatedUserDTO) {
|
|
this.userId = dto.userId;
|
|
this.email = dto.email;
|
|
this.displayName = dto.displayName;
|
|
}
|
|
|
|
// Note: The generated DTO doesn't have these fields
|
|
// These will need to be added when the OpenAPI spec is updated
|
|
driverId?: string;
|
|
isAuthenticated: boolean = true;
|
|
|
|
/**
|
|
* Compatibility accessor.
|
|
* Some legacy components expect `session.user.*`.
|
|
*/
|
|
get user(): {
|
|
userId: string;
|
|
email: string;
|
|
displayName: string;
|
|
primaryDriverId?: string | null;
|
|
} {
|
|
return {
|
|
userId: this.userId,
|
|
email: this.email,
|
|
displayName: this.displayName,
|
|
primaryDriverId: this.driverId ?? null,
|
|
};
|
|
}
|
|
|
|
/** UI-specific: User greeting */
|
|
get greeting(): string {
|
|
return `Hello, ${this.displayName}!`;
|
|
}
|
|
|
|
/** 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';
|
|
}
|
|
}
|