website refactor
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { AuthenticatedUserDTO } from '../types/generated/AuthenticatedUserDTO';
|
||||
import { AuthenticatedUserDTO } from '@/lib/types/generated/AuthenticatedUserDTO';
|
||||
|
||||
export class SessionViewModel {
|
||||
userId: string;
|
||||
@@ -6,31 +6,28 @@ export class SessionViewModel {
|
||||
displayName: string;
|
||||
avatarUrl?: string | null;
|
||||
role?: string;
|
||||
driverId?: string;
|
||||
isAuthenticated: boolean = true;
|
||||
|
||||
constructor(dto: AuthenticatedUserDTO) {
|
||||
this.userId = dto.userId;
|
||||
this.email = dto.email;
|
||||
this.displayName = dto.displayName;
|
||||
|
||||
const anyDto = dto as unknown as { primaryDriverId?: unknown; driverId?: unknown; avatarUrl?: unknown; role?: unknown };
|
||||
if (typeof anyDto.primaryDriverId === 'string' && anyDto.primaryDriverId) {
|
||||
this.driverId = anyDto.primaryDriverId;
|
||||
} else if (typeof anyDto.driverId === 'string' && anyDto.driverId) {
|
||||
this.driverId = anyDto.driverId;
|
||||
// Use the optional fields from the DTO
|
||||
if (dto.primaryDriverId) {
|
||||
this.driverId = dto.primaryDriverId;
|
||||
}
|
||||
if (anyDto.avatarUrl !== undefined) {
|
||||
this.avatarUrl = anyDto.avatarUrl as string | null;
|
||||
|
||||
if (dto.avatarUrl !== undefined) {
|
||||
this.avatarUrl = dto.avatarUrl;
|
||||
}
|
||||
if (typeof anyDto.role === 'string' && anyDto.role) {
|
||||
this.role = anyDto.role;
|
||||
|
||||
if (dto.role) {
|
||||
this.role = dto.role;
|
||||
}
|
||||
}
|
||||
|
||||
// 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.*`.
|
||||
@@ -73,4 +70,4 @@ export class SessionViewModel {
|
||||
get authStatusDisplay(): string {
|
||||
return this.isAuthenticated ? 'Logged In' : 'Logged Out';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user