Initializes the ExerciseService with required repository dependencies.
Prisma database client for repository initialization
Creates a new exercise with comprehensive validation and type-specific data verification.
Validates exercise ID uniqueness and performs type-specific data validation to ensure the exercise data conforms to the expected schema for the specified exercise type.
Exercise creation data including ID, type, and type-specific data
Unique exercise identifier
Type of exercise
Type-specific exercise data object
The newly created exercise object
// Create a fill-in-the-blank exercise
const exercise = await exerciseService.createExercise({
id: 'exercise-fill-greeting',
exercise_type: 'fill-in-the-blank',
data: {
text: 'Hello, my name is _____ and I am from _____.',
blanks: [
{ position: 18, correct_answers: ['John', 'Jane'], hints: ['common name'] },
{ position: 40, correct_answers: ['Spain', 'Mexico'], hints: ['country'] }
]
}
});
Retrieves a single exercise by its unique identifier.
The unique exercise identifier
The exercise object with all its properties and type-specific data
Retrieves paginated exercises across all types in the system.
Optional
options: QueryOptions = {}Query options for pagination, sorting, and filtering
Page number for pagination
Number of items per page
Field to sort by
Sort direction
Additional filters to apply
Paginated exercise results with metadata
Retrieves paginated exercises filtered by a specific exercise type.
Validates the exercise type against supported types before querying and returns exercises matching the specified type with pagination support.
The exercise type to filter by
Optional
options: QueryOptions = {}Query options for pagination, sorting, and filtering
Page number for pagination
Number of items per page
Field to sort by
Sort direction
Paginated exercise results filtered by type
Updates an existing exercise with partial data and comprehensive validation.
Validates exercise existence and performs type-specific data validation when exercise data is updated. If only data is provided without type, validates against the current exercise type to maintain data consistency.
The unique exercise identifier
Partial exercise data for update
Updated exercise type
Updated type-specific exercise data
The updated exercise object
Permanently deletes an exercise and removes it from all lesson assignments.
Validates exercise existence before deletion and ensures the operation completes successfully. This operation may cascade to remove exercise assignments from lessons.
The unique exercise identifier
Resolves when deletion is complete
Retrieves multiple exercises by their unique identifiers in a single query.
Efficiently fetches multiple exercises by their IDs, returning them in the order found in the database. Returns an empty array if no IDs are provided.
Array of unique exercise identifiers
Array of exercise objects matching the provided IDs
Service class for comprehensive exercise management operations within the WayrApp content system.
Provides complete CRUD functionality for exercises with type-specific validation, data integrity enforcement, and comprehensive business logic for all supported exercise types in the platform.