Creates a new UserService instance
Repository instance for data access operations
Retrieves a user by their unique identifier
The unique user identifier
Promise resolving to user object or null if not found
Creates a new user account without password (for OAuth or external auth)
User data for account creation
User's email address (required)
User's username (optional)
User's country code (optional)
User's profile picture URL (optional)
User's role (defaults to 'student')
Promise resolving to the created user object
Updates existing user information
The unique user identifier
Object containing fields to update
New username (optional)
New country code (optional)
New profile picture URL (optional)
Account active status (optional)
User role (optional)
Promise resolving to the updated user object
Creates a new user account with password hashing for standard registration
User data including password
User's email address (required)
User's plain text password (required)
User's username (optional)
User's country code (optional)
User's profile picture URL (optional)
User's role (defaults to 'student')
User's plain text password (required)
Promise resolving to the created user object (without password hash)
Verifies a user's password against the stored hash
The unique user identifier
The plain text password to verify
Promise resolving to true if password is valid, false otherwise
Authenticates a user by email and password combination
The user's email address
The user's plain text password
Promise resolving to user object if credentials are valid, null otherwise
Updates the user's last login timestamp to current time
The unique user identifier
Promise that resolves when update is complete This method is designed to be non-blocking and will not throw errors if the update fails, only logging warnings to prevent login flow interruption
Deactivates a user account by setting is_active to false
The unique user identifier
Promise resolving to the updated user object
Activates a user account by setting is_active to true
The unique user identifier
Promise resolving to the updated user object
Checks if a user exists by their unique identifier
The unique user identifier
Promise resolving to true if user exists, false otherwise
Retrieves a paginated list of users with optional filtering and sorting
Optional
options: QueryOptions = {}Query options for pagination and filtering
Page number for pagination
Number of items per page
Field to sort by
Sort order
Filters to apply
Filter by user role
Filter by active status
Search in email and username
Promise resolving to paginated user results
Updates a user's password after verifying their current password
The unique user identifier
The user's current plain text password
The new plain text password to set
Promise resolving to true when password is successfully updated
Retrieves a user's profile information without sensitive data
The unique user identifier
Promise resolving to user profile or null if not found
UserService - Core business logic service for user management operations
Provides comprehensive user management functionality including authentication, profile management, and account lifecycle operations. Acts as the business logic layer between controllers and the data repository.
UserService
Example