WayrApp Backend & Ecosystem Documentation - v1.0.0
    Preparing search index...

    Class LessonController

    HTTP controller class for comprehensive lesson management operations within the WayrApp content system.

    Provides RESTful API endpoints for lesson CRUD operations, exercise assignment management, and maintains proper HTTP response formatting with comprehensive error handling. Integrates with Express middleware for authentication, validation, and error propagation.

    Index

    Constructors

    Methods

    • Creates a new lesson within a specified module with comprehensive validation.

      Extracts module ID from URL parameters, validates request body against CreateLessonSchema, delegates lesson creation to the service layer, and returns a standardized API response with HTTP 201 status on successful creation.

      Parameters

      • req: Request

        Express request object containing moduleId in params and lesson data in body

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling middleware

      Returns Promise<void>

      Resolves when response is sent or error is passed to middleware

      When module ID is missing from URL parameters

      When request body validation fails against CreateLessonSchema

      When service layer lesson creation fails

      // POST /api/modules/module-greetings/lessons
      // Request body: { "id": "lesson-basic-intro", "experience_points": 50, "order": 1 }
      // Response: { "data": { lesson object }, "success": true, "timestamp": "2024-01-01T00:00:00.000Z" }
    • Retrieves a single lesson by its unique identifier with comprehensive validation. Uses composite key lookup to prevent horizontal access vulnerabilities.

      Extracts lesson ID and module ID from URL parameters, validates parameter presence, delegates lesson retrieval to the service layer, and returns a standardized API response with HTTP 200 status containing the lesson data.

      Parameters

      • req: Request

        Express request object containing lesson ID and module ID in params

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling middleware

      Returns Promise<void>

      Resolves when response is sent or error is passed to middleware

      When lesson ID or module ID is missing from URL parameters

      When service layer lesson retrieval fails or lesson not found

      // GET /api/modules/module-greetings/lessons/lesson-basic-intro
      // Response: { "data": { lesson object }, "success": true, "timestamp": "2024-01-01T00:00:00.000Z" }
    • Retrieves paginated lessons belonging to a specific module with query support.

      Extracts module ID from URL parameters, processes query parameters for pagination and sorting, delegates lesson retrieval to the service layer, and returns a standardized API response with HTTP 200 status. Includes pagination metadata in response headers for client consumption.

      Parameters

      • req: Request

        Express request object containing moduleId in params and query options

      • res: Response

        Express response object for sending HTTP response with pagination headers

      • next: NextFunction

        Express next function for error handling middleware

      Returns Promise<void>

      Resolves when response is sent or error is passed to middleware

      When module ID is missing from URL parameters

      When service layer lesson retrieval fails or module not found

      // GET /api/modules/module-greetings/lessons?page=1&limit=10&sortBy=order&sortOrder=asc
      // Response headers: X-Total-Count, X-Total-Pages, X-Current-Page, X-Has-Next, X-Has-Prev
      // Response: { "data": [lesson objects], "success": true, "timestamp": "2024-01-01T00:00:00.000Z" }
    • Updates an existing lesson with partial data and comprehensive validation. Uses composite key lookup to prevent horizontal access vulnerabilities.

      Extracts lesson ID and module ID from URL parameters, validates request body against UpdateLessonSchema, filters out undefined values from update data, delegates lesson update to the service layer, and returns a standardized API response with HTTP 200 status containing updated lesson data.

      Parameters

      • req: Request

        Express request object containing lesson ID and module ID in params and update data in body

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling middleware

      Returns Promise<void>

      Resolves when response is sent or error is passed to middleware

      When lesson ID or module ID is missing from URL parameters

      When request body validation fails against UpdateLessonSchema

      When service layer lesson update fails or lesson not found

      // PUT /api/modules/module-greetings/lessons/lesson-basic-intro
      // Request body: { "experience_points": 75, "order": 2 }
      // Response: { "data": { updated lesson object }, "success": true, "timestamp": "2024-01-01T00:00:00.000Z" }
    • Permanently deletes a lesson and all its associated exercise assignments. Uses composite key lookup to prevent horizontal access vulnerabilities.

      Extracts lesson ID and module ID from URL parameters, validates parameter presence, delegates lesson deletion to the service layer, and returns a standardized API response with HTTP 204 status indicating successful deletion without content.

      Parameters

      • req: Request

        Express request object containing lesson ID and module ID in params

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling middleware

      Returns Promise<void>

      Resolves when response is sent or error is passed to middleware

      When lesson ID or module ID is missing from URL parameters

      When service layer lesson deletion fails or lesson not found

      // DELETE /api/modules/module-greetings/lessons/lesson-basic-intro
      // Response: { "success": true, "message": "Lesson deleted successfully", "timestamp": "2024-01-01T00:00:00.000Z" }
    • Assigns an exercise to a lesson at a specific order position with comprehensive validation.

      Extracts lesson ID from URL parameters, validates request body against AssignExerciseToLessonSchema, delegates exercise assignment to the service layer, and returns a standardized API response with HTTP 201 status containing the created lesson-exercise assignment relationship.

      Parameters

      • req: Request

        Express request object containing lessonId in params and assignment data in body

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling middleware

      Returns Promise<void>

      Resolves when response is sent or error is passed to middleware

      When lesson ID is missing from URL parameters

      When request body validation fails against AssignExerciseToLessonSchema

      When service layer exercise assignment fails

      // POST /api/lessons/lesson-basic-intro/exercises
      // Request body: { "exercise_id": "exercise-translate-hello", "order": 1 }
      // Response: { "data": { lesson-exercise assignment }, "success": true, "timestamp": "2024-01-01T00:00:00.000Z" }
    • Removes an exercise assignment from a lesson with comprehensive validation.

      Extracts lesson ID and exercise ID from URL parameters, validates parameter presence, delegates exercise unassignment to the service layer, and returns a standardized API response with HTTP 204 status indicating successful removal without content.

      Parameters

      • req: Request

        Express request object containing lessonId and exerciseId in params

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling middleware

      Returns Promise<void>

      Resolves when response is sent or error is passed to middleware

      When lesson ID is missing from URL parameters

      When exercise ID is missing from URL parameters

      When service layer exercise unassignment fails

      // DELETE /api/lessons/lesson-basic-intro/exercises/exercise-translate-hello
      // Response: { "success": true, "message": "Exercise unassigned from lesson successfully", "timestamp": "2024-01-01T00:00:00.000Z" }
    • Retrieves all exercises assigned to a specific lesson in their defined order.

      Extracts lesson ID from URL parameters, validates parameter presence, delegates exercise retrieval to the service layer, and returns a standardized API response with HTTP 200 status containing the ordered list of lesson-exercise assignments.

      Parameters

      • req: Request

        Express request object containing lessonId in params

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling middleware

      Returns Promise<void>

      Resolves when response is sent or error is passed to middleware

      When lesson ID is missing from URL parameters

      When service layer exercise retrieval fails or lesson not found

      // GET /api/lessons/lesson-basic-intro/exercises
      // Response: { "data": [lesson-exercise assignments], "success": true, "timestamp": "2024-01-01T00:00:00.000Z" }
    • Reorders exercises within a lesson by updating their position sequence.

      Extracts lesson ID from URL parameters, validates request body against ReorderExercisesSchema, delegates exercise reordering to the service layer, and returns a standardized API response with HTTP 200 status indicating successful reordering operation.

      Parameters

      • req: Request

        Express request object containing lessonId in params and exercise_ids array in body

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling middleware

      Returns Promise<void>

      Resolves when response is sent or error is passed to middleware

      When lesson ID is missing from URL parameters

      When request body validation fails against ReorderExercisesSchema

      When service layer exercise reordering fails

      // PUT /api/lessons/lesson-basic-intro/exercises/reorder
      // Request body: { "exercise_ids": ["exercise-translate-hello", "exercise-fill-blank", "exercise-match"] }
      // Response: { "success": true, "message": "Lesson exercises reordered successfully", "timestamp": "2024-01-01T00:00:00.000Z" }
    • Reorders lessons within a module by updating their position sequence.

      Extracts module ID from URL parameters, validates request body against ReorderLessonsSchema, delegates lesson reordering to the service layer, and returns a standardized API response with HTTP 200 status indicating successful reordering operation.

      Parameters

      • req: Request

        Express request object containing moduleId in params and lesson_ids array in body

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling middleware

      Returns Promise<void>

      Resolves when response is sent or error is passed to middleware

      When module ID is missing from URL parameters

      When request body validation fails against ReorderLessonsSchema

      When service layer lesson reordering fails

      // PUT /api/modules/module-basic-conversation/lessons/reorder
      // Request body: { "lesson_ids": ["lesson-greetings", "lesson-introductions", "lesson-farewells"] }
      // Response: { "success": true, "message": "Module lessons reordered successfully", "timestamp": "2024-01-01T00:00:00.000Z" }