Creates a new LessonRepository instance
Initialized Prisma client for database operations
Creates a new lesson in the database with automatic field mapping and default value assignment. Transforms DTO field names to match database schema and applies default experience points value.
Lesson creation data with all required fields
Unique identifier for the lesson
Parent module identifier
Experience points awarded for lesson completion (defaults to 10)
Order position within the parent module
Promise resolving to the created lesson with transformed field names
Retrieves a single lesson by its unique identifier and module ID with complete exercise information. Includes all assigned exercises with their details, ordered by exercise sequence within the lesson. Uses composite key lookup to prevent horizontal access vulnerabilities.
Unique identifier of the lesson to retrieve
Module identifier to ensure lesson belongs to the correct module
Promise resolving to lesson with exercises or null if not found
Retrieves a paginated list of lessons within a specific module with advanced filtering capabilities. Supports experience points range filtering, comprehensive sorting options, and includes complete exercise information for each lesson ordered by sequence within lessons.
Parent module identifier to filter lessons
Optional
options: QueryOptions = {}Query configuration options for filtering, pagination, and sorting
Page number for pagination (1-based)
Maximum number of lessons per page
Filter conditions (supports 'experience_points_min' and 'experience_points_max')
Field to sort by (must be in allowed sort fields)
Sort direction
Promise resolving to paginated lesson results with exercises
Retrieves a paginated list of all lessons with optional module filtering and comprehensive sorting. Supports cross-module lesson querying with module-based filtering and includes complete exercise information for each lesson ordered by sequence within lessons.
Optional
options: QueryOptions = {}Query configuration options for filtering, pagination, and sorting
Page number for pagination (1-based)
Maximum number of lessons per page
Filter conditions (supports 'module_id' filter)
Field to sort by (must be in allowed sort fields)
Sort direction
Promise resolving to paginated lesson results with exercises
Updates an existing lesson with partial data and field mapping transformation. Supports updating experience points and order position with complete exercise information returned in the updated lesson object. Uses composite key lookup to prevent horizontal access vulnerabilities.
Unique identifier of the lesson to update
Module identifier to ensure lesson belongs to the correct module
Partial lesson data with fields to update
Updated experience points value
Updated order position within the module
Promise resolving to updated lesson with complete exercise information
Deletes a lesson from the database by its unique identifier and module ID. Handles deletion gracefully with error catching to prevent application crashes. Cascade deletion will automatically remove associated lesson-exercise relationships. Uses composite key lookup to prevent horizontal access vulnerabilities.
Unique identifier of the lesson to delete
Module identifier to ensure lesson belongs to the correct module
Promise resolving to true if deletion succeeded, false if failed or lesson not found
Checks if a lesson exists in the database by its unique identifier. Uses efficient count query to determine existence without retrieving full lesson data.
Unique identifier of the lesson to check
Promise resolving to true if lesson exists, false otherwise
Assigns an exercise to a lesson at a specific order position. Creates a new lesson-exercise relationship with the specified order for exercise sequencing.
Unique identifier of the lesson
Unique identifier of the exercise to assign
Order position of the exercise within the lesson sequence
Promise resolving to the created lesson-exercise assignment with exercise details
Removes an exercise assignment from a lesson. Deletes the lesson-exercise relationship while preserving both the lesson and exercise entities.
Unique identifier of the lesson
Unique identifier of the exercise to unassign
Promise resolving to true if unassignment succeeded, false if failed or assignment not found
Retrieves all exercises assigned to a specific lesson ordered by their sequence. Returns complete exercise information with assignment details for lesson content delivery.
Unique identifier of the lesson
Promise resolving to array of lesson-exercise assignments with exercise details, ordered by sequence
Reorders exercises within a lesson using atomic transaction operations. Updates the order positions of all specified exercises to match the provided sequence, ensuring data consistency through database transaction isolation.
Unique identifier of the lesson
Array of exercise IDs in the desired order sequence
Promise resolving to true if reordering succeeded, false if failed
Reorders lessons within a module using atomic transaction operations. Updates the order positions of all specified lessons to match the provided sequence, ensuring data consistency through database transaction isolation.
This method performs atomic updates of lesson order values within a single transaction, preventing race conditions and maintaining referential integrity. Each lesson's order is updated based on its position in the provided lesson IDs array, starting from 1.
The unique module identifier containing the lessons
Array of lesson IDs in their new desired order sequence
Promise resolving to true if reordering succeeded, false if failed
Lesson repository class providing comprehensive data access operations for lesson management and exercise assignment operations. Implements standardized CRUD operations with advanced querying, filtering, pagination, and sophisticated exercise relationship management.