Creates a new UserRepository instance
Prisma client instance for database operations
Creates a new user without password authentication
User data for creation
User's email address (required, unique)
User's username (optional, unique if provided)
Two-letter country code (optional)
URL to user's profile picture (optional)
User's role in the system (defaults to 'student')
Promise resolving to the created user object
Creates a new user with password hash for authentication
User data including password hash
User's email address (required, unique)
User's username (optional, unique if provided)
Two-letter country code (optional)
URL to user's profile picture (optional)
User's role in the system (defaults to 'student')
Hashed password for authentication
Hashed password for authentication
Promise resolving to the created user object
Retrieves minimal user data with password hash by their unique identifier for authentication
User's unique identifier (UUID)
Promise resolving to minimal user auth data or null if not found
Retrieves minimal user data with password hash by their email address for authentication
User's email address
Promise resolving to minimal user auth data or null if not found
Throws DATABASE_ERROR for database-related failures
This method uses Prisma's select to fetch only essential authentication fields, reducing data exposure and improving performance. The returned UserAuthData contains only the minimum information needed for login workflows.
const authData = await userRepository.findByEmailWithPassword('user@example.com');
if (authData && authData.isActive && authData.passwordHash) {
const isValid = await comparePassword(plainPassword, authData.passwordHash);
if (isValid) {
// Authentication successful, fetch full user data if needed
const fullUser = await userRepository.findById(authData.id);
}
}
Updates existing user information with validation
User's unique identifier (UUID)
Object containing fields to update
New username (optional, must be unique if provided)
New country code (optional)
New profile picture URL (optional)
New active status (optional)
Promise resolving to the updated user object
Retrieves paginated list of users with filtering and sorting capabilities
Optional
options: QueryOptions = {}Query options for pagination, filtering, and sorting
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 fields
Promise resolving to paginated result with users and pagination metadata
Updates user password hash securely
User's unique identifier (UUID)
New hashed password
Promise resolving to the updated user object
Updates user's last login timestamp for tracking purposes
User's unique identifier (UUID)
Optional
date: Date = ...Login timestamp (defaults to current date/time)
Promise resolving to the updated user object
UserRepository - Data access layer for user operations using Prisma ORM
UserRepository Provides comprehensive data access operations for user management including CRUD operations, authentication queries, and pagination. Acts as the data access layer between the business logic service and the PostgreSQL database through Prisma ORM.