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

    Class ContentController

    Content controller class providing comprehensive REST API endpoints for hierarchical content management. Implements full CRUD operations for courses, levels, sections, and modules with advanced querying, pagination, caching, and security features.

    Index

    Constructors

    Methods

    • Creates a new course with comprehensive validation and proper response formatting. Validates request data using Zod schema, handles optional properties correctly, and returns standardized API response with created course data.

      Parameters

      • req: Request

        Express request object with course data in body

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling

      Returns Promise<void>

      Promise that resolves when response is sent

      When validation fails or course creation encounters errors

      When course with same ID already exists (handled by service layer)

      // POST /api/courses
      // Request body: { id: 'spanish-101', source_language: 'en', target_language: 'es', name: 'Spanish Basics' }
      // Response: { data: Course, success: true, timestamp: '2024-01-01T00:00:00.000Z' }
    • Retrieves a single course by its unique identifier with complete course information. Validates course ID parameter and returns standardized API response with course data.

      Parameters

      • req: Request

        Express request object with course ID in params

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling

      Returns Promise<void>

      Promise that resolves when response is sent

      When course ID parameter is missing or invalid

      When course with specified ID is not found (handled by service layer)

      // GET /api/courses/spanish-101
      // Response: { data: Course, success: true, timestamp: '2024-01-01T00:00:00.000Z' }
    • Retrieves a paginated list of courses with advanced filtering, searching, and sorting capabilities. Supports pagination middleware integration, search functionality, and comprehensive response headers for client-side pagination handling.

      Parameters

      • req: Request

        Express request object with pagination options from middleware or query params

      • res: Response

        Express response object for sending HTTP response with pagination headers

      • next: NextFunction

        Express next function for error handling

      Returns Promise<void>

      Promise that resolves when response is sent

      // GET /api/courses?page=1&limit=10&search=spanish&sortBy=name&sortOrder=asc
      // Response: { data: Course[], success: true, timestamp: '2024-01-01T00:00:00.000Z' }
      // Headers: X-Total-Count, X-Page, X-Per-Page, X-Total-Pages, Link
    • Updates an existing course with partial data and comprehensive validation. Validates course ID parameter and update data, then returns updated course information.

      Parameters

      • req: Request

        Express request object with course 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

      Returns Promise<void>

      Promise that resolves when response is sent

      When course ID parameter is missing or invalid

      When course with specified ID is not found (handled by service layer)

      When update data validation fails

      // PUT /api/courses/spanish-101
      // Request body: { name: 'Advanced Spanish', description: 'Updated description' }
      // Response: { data: Course, success: true, timestamp: '2024-01-01T00:00:00.000Z' }
    • Deletes a course and all associated content with cascade deletion handling. Validates course ID parameter and performs secure deletion with proper response formatting.

      Parameters

      • req: Request

        Express request object with course ID in params

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling

      Returns Promise<void>

      Promise that resolves when response is sent

      When course ID parameter is missing or invalid

      When course with specified ID is not found (handled by service layer)

      When deletion fails due to database constraints

      // DELETE /api/courses/spanish-101
      // Response: { success: true, message: 'Course deleted successfully', timestamp: '2024-01-01T00:00:00.000Z' }
    • Retrieves a complete packaged course with all hierarchical content and advanced caching support. Implements conditional requests using If-Modified-Since headers and comprehensive caching strategies for optimal content delivery performance.

      Parameters

      • req: Request

        Express request object with course ID in params and optional If-Modified-Since header

      • res: Response

        Express response object for sending HTTP response with caching headers

      • next: NextFunction

        Express next function for error handling

      Returns Promise<void>

      Promise that resolves when response is sent

      When course ID parameter is missing or invalid

      When course with specified ID is not found (handled by service layer)

      // GET /api/courses/spanish-101/package
      // Headers: If-Modified-Since: Wed, 21 Oct 2015 07:28:00 GMT
      // Response: { data: PackagedCourse, success: true, timestamp: '2024-01-01T00:00:00.000Z' }
      // Response Headers: Last-Modified, Cache-Control, ETag
    • Creates a new level within a specified course with hierarchical relationship management. Validates course ID parameter, merges it with level data, and creates the level with proper parent-child relationship establishment.

      Parameters

      • req: Request

        Express request object with course ID in params and level data in body

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling

      Returns Promise<void>

      Promise that resolves when response is sent

      When course ID parameter is missing or invalid

      When parent course is not found (handled by service layer)

      When level data validation fails

      // POST /api/courses/spanish-101/levels
      // Request body: { id: 'level-beginner', code: 'A1', name: 'Beginner Level', order: 1 }
      // Response: { data: Level, success: true, timestamp: '2024-01-01T00:00:00.000Z' }
    • Retrieves a single level by its unique identifier with complete level information. Validates level ID parameter and returns standardized API response with level data.

      Parameters

      • req: Request

        Express request object with level ID in params

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling

      Returns Promise<void>

      Promise that resolves when response is sent

      When level ID parameter is missing or invalid

      When level with specified ID is not found (handled by service layer)

    • Retrieves a paginated list of levels within a specific course with hierarchical ordering. Supports pagination middleware integration, search functionality, and proper ordering by level sequence within the course structure.

      Parameters

      • req: Request

        Express request object with course ID in params and pagination options

      • res: Response

        Express response object for sending HTTP response with pagination headers

      • next: NextFunction

        Express next function for error handling

      Returns Promise<void>

      Promise that resolves when response is sent

      When course ID parameter is missing or invalid

      When parent course is not found (handled by service layer)

    • Updates an existing level with partial data and comprehensive validation. Validates level ID parameter and update data, then returns updated level information.

      Parameters

      • req: Request

        Express request object with level 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

      Returns Promise<void>

      Promise that resolves when response is sent

      When level ID parameter is missing or invalid

      When level with specified ID is not found (handled by service layer)

    • Deletes a level and all associated content with cascade deletion handling. Validates level ID parameter and performs secure deletion with proper response formatting.

      Parameters

      • req: Request

        Express request object with level ID in params

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling

      Returns Promise<void>

      Promise that resolves when response is sent

      When level ID parameter is missing or invalid

      When level with specified ID is not found (handled by service layer)

    • Creates a new section within a specified level with hierarchical relationship management. Validates level ID parameter, merges it with section data, and creates the section with proper parent-child relationship establishment.

      Parameters

      • req: Request

        Express request object with level ID in params and section data in body

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling

      Returns Promise<void>

      Promise that resolves when response is sent

      When level ID parameter is missing or invalid

      When parent level is not found (handled by service layer)

    • Retrieves a single section by its unique identifier with complete section information. Validates section ID parameter and returns standardized API response with section data.

      Parameters

      • req: Request

        Express request object with section ID in params

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling

      Returns Promise<void>

      Promise that resolves when response is sent

    • Retrieves a paginated list of sections within a specific level with hierarchical ordering. Supports pagination middleware integration, search functionality, and proper ordering by section sequence within the level structure.

      Parameters

      • req: Request

        Express request object with level ID in params and pagination options

      • res: Response

        Express response object for sending HTTP response with pagination headers

      • next: NextFunction

        Express next function for error handling

      Returns Promise<void>

      Promise that resolves when response is sent

    • Updates an existing section with partial data and comprehensive validation. Validates section ID parameter and update data, then returns updated section information.

      Parameters

      • req: Request

        Express request object with section 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

      Returns Promise<void>

      Promise that resolves when response is sent

    • Deletes a section and all associated content with cascade deletion handling. Validates section ID parameter and performs secure deletion with proper response formatting.

      Parameters

      • req: Request

        Express request object with section ID in params

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling

      Returns Promise<void>

      Promise that resolves when response is sent

    • Creates a new module within a specified section with hierarchical relationship management. Validates section ID parameter, merges it with module data, and creates the module with proper parent-child relationship establishment and module type validation.

      Parameters

      • req: Request

        Express request object with section ID in params and module data in body

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling

      Returns Promise<void>

      Promise that resolves when response is sent

      When section ID parameter is missing or invalid

      When parent section is not found (handled by service layer)

    • Retrieves a single module by its unique identifier with complete module information. Validates module ID parameter and returns standardized API response with module data including module type and hierarchical context.

      Parameters

      • req: Request

        Express request object with module ID in params

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling

      Returns Promise<void>

      Promise that resolves when response is sent

    • Retrieves a paginated list of modules within a specific section with type filtering support. Supports pagination middleware integration, search functionality, module type filtering, and proper ordering by module sequence within the section structure.

      Parameters

      • req: Request

        Express request object with section ID in params and pagination options

      • res: Response

        Express response object for sending HTTP response with pagination headers

      • next: NextFunction

        Express next function for error handling

      Returns Promise<void>

      Promise that resolves when response is sent

    • Updates an existing module with partial data and comprehensive validation. Validates module ID parameter and update data, supports module type changes, and returns updated module information with proper type validation.

      Parameters

      • req: Request

        Express request object with 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

      Returns Promise<void>

      Promise that resolves when response is sent

    • Deletes a module and all associated content with cascade deletion handling. Validates module ID parameter and performs secure deletion with proper response formatting. Handles deletion of associated lessons and exercises through cascade operations.

      Parameters

      • req: Request

        Express request object with module ID in params

      • res: Response

        Express response object for sending HTTP response

      • next: NextFunction

        Express next function for error handling

      Returns Promise<void>

      Promise that resolves when response is sent

    • Reorders modules within a section by updating their position sequence.

      Extracts section ID from URL parameters, validates request body against ReorderModulesSchema, delegates module 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 sectionId in params and module_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 section ID is missing from URL parameters

      When request body validation fails against ReorderModulesSchema

      When service layer module reordering fails

      // PUT /api/sections/section-basic-conversation/modules/reorder
      // Request body: { "module_ids": ["module-greetings", "module-introductions", "module-farewells"] }
      // Response: { "success": true, "message": "Section modules reordered successfully", "timestamp": "2024-01-01T00:00:00.000Z" }
    • Reorders sections within a level by updating their position sequence.

      Extracts level ID from URL parameters, validates request body against ReorderSectionsSchema, delegates section 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 level ID in params and section IDs in body

      • res: Response

        Express response object for sending the API 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 level ID is missing from URL parameters

      When request body validation fails against ReorderSectionsSchema

      When service layer section reordering fails

      // PUT /api/levels/level-basic-conversation/sections/reorder
      // Request body: { "section_ids": ["section-greetings", "section-introductions", "section-farewells"] }
      // Response: { "success": true, "message": "Level sections reordered successfully", "timestamp": "2024-01-01T00:00:00.000Z" }
    • Reorders levels within a course by updating their position sequence.

      Extracts course ID from URL parameters, validates request body against ReorderLevelsSchema, delegates level 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 course ID in params and level IDs in body

      • res: Response

        Express response object for sending the API 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 course ID is missing from URL parameters

      When request body validation fails against ReorderLevelsSchema

      When service layer level reordering fails

      // PUT /api/courses/course-spanish-101/levels/reorder
      // Request body: { "level_ids": ["level-beginner", "level-intermediate", "level-advanced"] }
      // Response: { "success": true, "message": "Course levels reordered successfully", "timestamp": "2024-01-01T00:00:00.000Z" }