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

    Module ExerciseRoutes

    Express routing configuration for exercise management operations within the WayrApp content management system.

    This module provides REST API route definitions for managing exercises, which are the fundamental interactive learning components within the WayrApp platform. Exercises represent individual learning activities that can be assigned to lessons and support multiple types including translation, fill-in-the-blank, true/false, pairs matching, informative content, and ordering tasks. The routes support full CRUD operations with comprehensive validation and role-based access control.

    The module implements a factory function pattern that accepts a PrismaClient instance and returns a configured Express router with all exercise-related endpoints. This design supports dependency injection and enables clean separation between route configuration and business logic. All routes include comprehensive input validation using Zod schemas, role-based authentication middleware, and standardized error handling.

    Key architectural features include comprehensive CRUD operations for exercise management, type-specific exercise filtering and retrieval, comprehensive input validation with exercise type enumeration, role-based access control (admin for deletion, content_creator for management), standardized API response formatting with proper HTTP status codes, and support for six different exercise types with type-specific data structures.

    The routes are mounted at the API base path in the main application and integrate with the ExerciseController for business logic execution. This module serves as a critical component of the content management system, enabling content creators and administrators to create and manage interactive learning activities that form the core educational experience within the platform.

    Exequiel Trujillo

    1.0.0

    // Mount exercise routes in main application
    import { createExerciseRoutes } from '@/modules/content/routes/exerciseRoutes';
    import { prisma } from '@/shared/database/connection';

    const API_BASE = '/api/v1';
    app.use(API_BASE, createExerciseRoutes(prisma));
    // Available exercise management endpoints:
    // GET /api/v1/exercises - List all exercises with filtering
    // POST /api/v1/exercises - Create exercise (content_creator/admin)
    // GET /api/v1/exercises/:id - Get exercise by ID
    // PUT /api/v1/exercises/:id - Update exercise (content_creator/admin)
    // DELETE /api/v1/exercises/:id - Delete exercise (admin only)
    // GET /api/v1/exercises/type/:type - Get exercises by type
    // Supported exercise types:
    // - translation: Language translation exercises
    // - fill-in-the-blank: Complete missing words or phrases
    // - vof: True/false or verification exercises
    // - pairs: Match related items or concepts
    // - informative: Educational content presentation
    // - ordering: Arrange items in correct sequence

    Functions

    createExerciseRoutes