clean-jsdoc-theme TypeDoc APIv0.0.0

User

Source: User.ts:176

User class representing a system user

Remarks

This class provides a full implementation of the IUser interface with additional utility methods for user management.

Example

CODE
Creating a new user:
```typescript
const user = new User(\{
  id: 'uuid-here',
  username: 'johndoe',
  displayName: 'John Doe',
  role: UserRole.User,
  status: AccountStatus.Active,
  contact: \{ email: 'john@example.com' \},
  preferences: \{
    theme: 'dark',
    language: 'en',
    timezone: 'America/New_York',
    notifications: \{ marketing: false, security: true, updates: true, digest: false \}
  \},
  createdAt: new Date(),
  updatedAt: new Date()
\})
```

Constructors

new User(data: IUser): User

Parameters

  • data (IUser) — User data to initialize the instance

Returns

User

Implements


Properties

contact: ContactInfo

Implementation of contact

Contact information

createdAt: Date

readonly
User.ts:192

Implementation of createdAt

Account creation timestamp

displayName: string

Implementation of displayName

Display name

id: string

readonly
User.ts:178

Implementation of id

Unique user identifier (UUID v4)

lastLoginAt: Date

Implementation of lastLoginAt

Last login timestamp

preferences: UserPreferences

Implementation of preferences

User preferences

role: UserRole

Implementation of role

User's role in the system

status: AccountStatus

Implementation of status

Current account status

updatedAt: Date

Implementation of updatedAt

Last update timestamp

username: string

Implementation of username

Username (unique, alphanumeric)

Methods

isActive(): boolean

Checks if the user account is active

Returns

  • boolean — True if account status is Active

isAdmin(): boolean

Checks if the user has admin privileges

Returns

  • boolean — True if user is Admin or SuperAdmin

Example

CODE
if (user.isAdmin()) {
  // Show admin panel
}

recordLogin(): void

Records a login event

Returns

  • void

toJSON(): IUser

Converts user to a JSON-serializable object

Returns

  • IUser — Plain object representation

updatePreferences(updates: Partial<UserPreferences>): this

Updates user preferences

Parameters

Returns

  • this — The updated user instance

Example

CODE
user.updatePreferences({
  theme: 'dark',
  language: 'zh'
})

Static Methods

fromJSON(json: string | IUser): User

Creates a User instance from JSON data

Parameters

  • json (string | IUser) — JSON string or parsed object

Returns

  • User — New User instance

Throws

  • SyntaxError If JSON string is invalid

Example

CODE
const user = User.fromJSON('{"id":"...","username":"johndoe",...}')