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

    Module ContentService

    Business logic service for managing hierarchical educational content in WayrApp.

    This service orchestrates the complete lifecycle of educational content through this hierarchy: Courses → Levels → Sections → Modules → Lessons → Exercises. It serves as the primary business logic layer between REST API controllers and data access repositories, implementing comprehensive validation, intelligent caching, and complex operations like packaged course generation for offline mobile support.

    The ContentService ensures data integrity through hierarchical validation, maintains referential consistency across all content operations, and provides optimized caching strategies for performance. It handles the complete CRUD lifecycle for all content entities while maintaining cache coherence and providing specialized features like conditional content packaging with versioning support.

    Key architectural responsibilities include hierarchical content validation (ensuring parent entities exist before creating children), unique constraint enforcement (IDs, codes, ordering within parents), intelligent cache invalidation (automatically clearing related caches on content changes), packaged content generation for offline mobile apps with HTTP conditional request support, and comprehensive error handling with detailed AppError responses.

    The service integrates seamlessly with Prisma ORM for database operations, Redis caching for performance optimization, and provides TypeScript-first APIs with full type safety across the entire content management workflow.

    Exequiel Trujillo

    1.0.0

    // Basic service initialization and course creation
    import { ContentService } from '@/modules/content/services';
    import { PrismaClient } from '@prisma/client';

    const prisma = new PrismaClient();
    const contentService = new ContentService(prisma);

    // Create a complete course hierarchy
    const course = await contentService.createCourse({
    id: 'spanish-101',
    source_language: 'en',
    target_language: 'es',
    name: 'Spanish for Beginners',
    description: 'Learn Spanish from scratch',
    is_public: true
    });
    // Advanced usage with packaged content for offline support
    // Get packaged course with all hierarchical content
    const packagedCourse = await contentService.getPackagedCourse('spanish-101');

    // Conditional request to check for updates (HTTP 304 support)
    const updated = await contentService.getPackagedCourse('spanish-101', '2024-01-01T00:00:00Z');
    if (updated === null) {
    console.log('Course not modified since specified date');
    }
    // Hierarchical content creation with validation
    const level = await contentService.createLevel({
    id: 'spanish-101-a1',
    course_id: 'spanish-101',
    code: 'A1',
    name: 'Beginner Level',
    order: 1
    });

    const section = await contentService.createSection({
    id: 'spanish-101-a1-intro',
    level_id: 'spanish-101-a1',
    name: 'Introduction',
    order: 1
    });

    Classes

    ContentService