59 lines
2.0 KiB
TypeScript
59 lines
2.0 KiB
TypeScript
import type { AdminUserViewData } from '@/lib/view-data/AdminUserViewData';
|
|
import { ViewModel } from "../contracts/view-models/ViewModel";
|
|
import { UserStatusDisplay } from "@/lib/display-objects/UserStatusDisplay";
|
|
import { UserRoleDisplay } from "@/lib/display-objects/UserRoleDisplay";
|
|
import { DateDisplay } from "@/lib/display-objects/DateDisplay";
|
|
|
|
/**
|
|
* AdminUserViewModel
|
|
*
|
|
* View Model for admin user management.
|
|
* Transforms API DTO into UI-ready state with formatting and derived fields.
|
|
*/
|
|
export class AdminUserViewModel extends ViewModel {
|
|
private readonly data: AdminUserViewData;
|
|
|
|
constructor(data: AdminUserViewData) {
|
|
super();
|
|
this.data = data;
|
|
}
|
|
|
|
get id(): string { return this.data.id; }
|
|
get email(): string { return this.data.email; }
|
|
get displayName(): string { return this.data.displayName; }
|
|
get roles(): string[] { return this.data.roles; }
|
|
get status(): string { return this.data.status; }
|
|
get isSystemAdmin(): boolean { return this.data.isSystemAdmin; }
|
|
get createdAt(): string { return this.data.createdAt; }
|
|
get updatedAt(): string { return this.data.updatedAt; }
|
|
get lastLoginAt(): string | undefined { return this.data.lastLoginAt; }
|
|
get primaryDriverId(): string | undefined { return this.data.primaryDriverId; }
|
|
|
|
/** UI-specific: Role badges using Display Object */
|
|
get roleBadges(): string[] {
|
|
return this.roles.map(role => UserRoleDisplay.roleLabel(role));
|
|
}
|
|
|
|
/** UI-specific: Status badge label using Display Object */
|
|
get statusBadgeLabel(): string {
|
|
return UserStatusDisplay.statusLabel(this.status);
|
|
}
|
|
|
|
/** UI-specific: Status badge variant using Display Object */
|
|
get statusBadgeVariant(): string {
|
|
return UserStatusDisplay.statusVariant(this.status);
|
|
}
|
|
|
|
/** UI-specific: Formatted last login date */
|
|
get lastLoginFormatted(): string {
|
|
return this.lastLoginAt
|
|
? DateDisplay.formatShort(this.lastLoginAt)
|
|
: 'Never';
|
|
}
|
|
|
|
/** UI-specific: Formatted creation date */
|
|
get createdAtFormatted(): string {
|
|
return DateDisplay.formatShort(this.createdAt);
|
|
}
|
|
}
|