Creates a new ContentService instance with initialized repositories for all content entities.
Initializes all repository instances (CourseRepository, LevelRepository, SectionRepository, ModuleRepository) with the provided Prisma client, establishing the foundation for all content management operations with consistent database access patterns.
Prisma database client for data access operations across all repositories
Creates a new course with automatic ID generation if not provided.
Course creation data including optional ID, languages, name, and optional description
Optional unique identifier for the course (auto-generated if not provided)
Source language code (e.g., 'en')
Target language code (e.g., 'es')
Display name of the course
Optional course description
Whether the course is publicly accessible
The created course object with timestamps
Retrieves a paginated list of courses with optional filtering and sorting.
Optional
options: QueryOptions = {}Query options for pagination, sorting, and filtering
Page number for pagination
Number of items per page
Field to sort by
Sort order
Additional filters to apply
Search term for text-based filtering
Paginated result containing courses and pagination metadata
Updates an existing course with partial data and invalidates related caches.
The unique identifier of the course to update
Partial course data to update
Updated source language code
Updated target language code
Updated course name
Updated course description
Updated public visibility status
The updated course object
Creates a new level within a course with comprehensive validation.
Validates parent course existence, unique level ID, unique code within course, and unique order within course before creation.
Level creation data
Unique identifier for the level
ID of the parent course
Unique code within the course (e.g., 'A1', 'B2')
Display name of the level
Ordering position within the course
The created level object with timestamps
Retrieves all levels belonging to a specific course with pagination support.
The unique identifier of the parent course
Optional
options: QueryOptions = {}Query options for pagination and sorting
Page number for pagination
Number of items per page
Field to sort by (typically 'order')
Sort order
Paginated result containing levels and pagination metadata
Updates an existing level with validation for code and order uniqueness within the course.
The unique identifier of the level to update
Partial level data to update
Updated level code (must be unique within course)
Updated level name
Updated order position (must be unique within course)
The updated level object
Creates a new section within a level with validation for parent existence and order uniqueness.
Section creation data
Unique identifier for the section
ID of the parent level
Display name of the section
Ordering position within the level
The created section object with timestamps
Retrieves all sections belonging to a specific level with pagination support.
The unique identifier of the parent level
Optional
options: QueryOptions = {}Query options for pagination and sorting
Page number for pagination
Number of items per page
Field to sort by (typically 'order')
Sort order
Paginated result containing sections and pagination metadata
Updates an existing section with validation for order uniqueness within the level.
The unique identifier of the section to update
Partial section data to update
Updated section name
Updated order position (must be unique within level)
The updated section object
Creates a new module within a section with comprehensive validation.
Module creation data
Unique identifier for the module
ID of the parent section
Type of module content
Display name of the module
Ordering position within the section
The created module object with timestamps
Retrieves all modules belonging to a specific section with pagination support.
The unique identifier of the parent section
Optional
options: QueryOptions = {}Query options for pagination, sorting, and filtering
Page number for pagination
Number of items per page
Field to sort by (typically 'order')
Sort order
Additional filters (e.g., module_type)
Paginated result containing modules and pagination metadata
Updates an existing module with validation for order uniqueness within the section.
The unique identifier of the module to update
Partial module data to update
Updated module type
Updated module name
Updated order position (must be unique within section)
The updated module object
Generates a complete packaged course with all hierarchical content for offline support.
This method creates a comprehensive package containing the entire course hierarchy (course → levels → sections → modules → lessons → exercises) optimized for offline use. Implements intelligent caching with 15-minute TTL and supports conditional requests via If-Modified-Since headers for efficient bandwidth usage.
The unique identifier of the course to package
Optional
ifModifiedSince: stringOptional If-Modified-Since header value for conditional requests
Complete packaged course or null if not modified since specified date
// Get full packaged course
const packagedCourse = await contentService.getPackagedCourse('spanish-101');
// Conditional request to check for updates
const updated = await contentService.getPackagedCourse('spanish-101', '2024-01-01T00:00:00Z');
if (updated === null) {
console.log('Course not modified since specified date');
}
Reorders modules within a section by updating their position sequence.
Validates section existence, ensures all provided module IDs are currently assigned to the section, validates completeness of the reorder list, and prevents duplicates before applying the new module order.
The unique section identifier
Array of module IDs in their new desired order
Resolves when reordering is complete
Reorders sections within a level by updating their position sequence.
Validates level existence, ensures all provided section IDs are currently assigned to the level, validates completeness of the reorder list, and prevents duplicates before applying the new section order.
The unique level identifier
Array of section IDs in their new desired order
Resolves when reordering is complete
Reorders levels within a course by updating their position sequence.
Validates course existence, ensures all provided level IDs are currently assigned to the course, validates completeness of the reorder list, and prevents duplicates before applying the new level order.
The unique course identifier
Array of level IDs in their new desired order
Resolves when reordering is complete
Invalidates the packaged course cache when content is updated.
This method is automatically called by all content modification operations (create, update, delete) to ensure cache consistency across the content hierarchy.
The unique identifier of the course whose cache should be invalidated
Resolves when cache invalidation is complete
Main service class implementing comprehensive educational content management operations.
This class provides the complete business logic layer for managing the four-tier content hierarchy with built-in validation, intelligent caching, and specialized features like packaged content generation. All operations maintain referential integrity and automatically invalidate related caches when content is modified.
ContentService