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

    Module LessonService

    Lesson management service for the WayrApp language learning platform.

    This service provides complete CRUD operations for lessons within the content management system, handling lesson lifecycle management, exercise assignment, and ordering operations. It serves as the primary business logic layer for lesson-related operations, ensuring data integrity through comprehensive validation and maintaining referential consistency across the content hierarchy.

    The service manages lessons as part of the content structure: Course → Level → Section → Module → Lesson → Exercise. Each lesson belongs to a specific module and can contain multiple exercises in a defined order. The service handles complex operations like exercise assignment, reordering, and validation of hierarchical relationships while providing paginated results for efficient data retrieval.

    Key architectural responsibilities include lesson creation with module validation, lesson retrieval with pagination support, lesson updates with order conflict resolution, lesson deletion with dependency checks, exercise-to-lesson assignment management, and exercise reordering within lessons. The service integrates with repository layers for data persistence and provides comprehensive error handling for all business rule violations.

    Exequiel Trujillo

    1.0.0

    // Initialize service with Prisma client
    import { PrismaClient } from '@prisma/client';
    import { LessonService } from './LessonService';

    const prisma = new PrismaClient();
    const lessonService = new LessonService(prisma);

    // Create a new lesson
    const newLesson = await lessonService.createLesson({
    id: 'lesson-basic-intro',
    module_id: 'module-greetings',
    experience_points: 50,
    order: 1
    });

    // Get lessons by module with pagination
    const lessons = await lessonService.getLessonsByModule('module-greetings', {
    page: 1,
    limit: 10,
    sortBy: 'order',
    sortOrder: 'asc'
    });

    // Assign exercise to lesson
    const assignment = await lessonService.assignExerciseToLesson('lesson-basic-intro', {
    exercise_id: 'exercise-translate-hello',
    order: 1
    });

    Classes

    LessonService