Files
gridpilot.gg/apps/website/lib/view-models/AdminUserViewModel.ts
2026-01-24 01:07:43 +01:00

59 lines
2.0 KiB
TypeScript

import { DateFormatter } from "@/lib/formatters/DateFormatter";
import { UserRoleFormatter } from "@/lib/formatters/UserRoleFormatter";
import { UserStatusFormatter } from "@/lib/formatters/UserStatusFormatter";
import type { AdminUserViewData } from '@/lib/view-data/AdminUserViewData';
import { ViewModel } from "../contracts/view-models/ViewModel";
/**
* 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 => UserRoleFormatter.roleLabel(role));
}
/** UI-specific: Status badge label using Display Object */
get statusBadgeLabel(): string {
return UserStatusFormatter.statusLabel(this.status);
}
/** UI-specific: Status badge variant using Display Object */
get statusBadgeVariant(): string {
return UserStatusFormatter.statusVariant(this.status);
}
/** UI-specific: Formatted last login date */
get lastLoginFormatted(): string {
return this.lastLoginAt
? DateFormatter.formatShort(this.lastLoginAt)
: 'Never';
}
/** UI-specific: Formatted creation date */
get createdAtFormatted(): string {
return DateFormatter.formatShort(this.createdAt);
}
}