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

    Class ExerciseRepository

    Exercise repository class providing comprehensive data access operations for exercise management across multiple exercise types. Implements standardized CRUD operations with type-specific filtering, bulk operations, and advanced querying capabilities.

    Index

    Constructors

    Methods

    • Creates a new exercise in the database with automatic type transformation and field mapping. Transforms exercise type from API format (dash-separated) to database format (underscore-separated) and stores flexible JSON data structure for type-specific configurations.

      Parameters

      • data: CreateExerciseDto

        Exercise creation data with all required fields

        • id

          Unique identifier for the exercise

        • exercise_type

          Type of exercise (API format with dashes)

        • data

          Type-specific exercise configuration data as JSON object

      Returns Promise<Exercise>

      Promise resolving to the created exercise with transformed field names

      When database operation fails or constraint violations occur

    • Retrieves a single exercise by its unique identifier with complete type-specific data. Returns the exercise with transformed field names and type formatting for API compatibility.

      Parameters

      • id: string

        Unique identifier of the exercise to retrieve

      Returns Promise<null | Exercise>

      Promise resolving to exercise with type-specific data or null if not found

    • Retrieves a paginated list of all exercises with advanced filtering and sorting capabilities. Supports exercise type filtering with automatic format transformation and comprehensive sorting options for exercise discovery and management workflows.

      Parameters

      • Optionaloptions: QueryOptions = {}

        Query configuration options for filtering, pagination, and sorting

        • page

          Page number for pagination (1-based)

        • limit

          Maximum number of exercises per page

        • filters

          Filter conditions (supports 'exercise_type' filter)

        • sortBy

          Field to sort by (must be in allowed sort fields)

        • sortOrder

          Sort direction

      Returns Promise<PaginatedResult<Exercise>>

      Promise resolving to paginated exercise results with type-specific data

    • Updates an existing exercise with partial data and automatic type transformation. Supports updating exercise type and data with proper format conversion and field mapping. Handles undefined data values appropriately for JSON field updates.

      Parameters

      • id: string

        Unique identifier of the exercise to update

      • data: Partial<CreateExerciseDto>

        Partial exercise data with fields to update

        • exercise_type

          Updated exercise type (API format)

        • data

          Updated type-specific exercise configuration data

      Returns Promise<Exercise>

      Promise resolving to updated exercise with transformed field names

      When exercise is not found or database operation fails

    • Deletes an exercise from the database by its unique identifier. Handles deletion gracefully with error catching to prevent application crashes. Cascade deletion will automatically remove associated lesson-exercise relationships.

      Parameters

      • id: string

        Unique identifier of the exercise to delete

      Returns Promise<boolean>

      Promise resolving to true if deletion succeeded, false if failed or exercise not found

    • Checks if an exercise exists in the database by its unique identifier. Uses efficient count query to determine existence without retrieving full exercise data.

      Parameters

      • id: string

        Unique identifier of the exercise to check

      Returns Promise<boolean>

      Promise resolving to true if exercise exists, false otherwise

    • Retrieves a paginated list of exercises filtered by specific exercise type. Automatically transforms exercise type from API format to database format and provides comprehensive pagination and sorting capabilities for type-specific exercise discovery.

      Parameters

      • exerciseType: string

        Exercise type to filter by (API format with dashes: 'fill-in-the-blank', 'translation', etc.)

      • Optionaloptions: QueryOptions = {}

        Query configuration options for pagination and sorting

        • page

          Page number for pagination (1-based)

        • limit

          Maximum number of exercises per page

        • sortBy

          Field to sort by (must be in allowed sort fields)

        • sortOrder

          Sort direction

      Returns Promise<PaginatedResult<Exercise>>

      Promise resolving to paginated exercises of the specified type

    • Retrieves multiple exercises by their unique identifiers in a single database query. Optimized for bulk operations such as lesson assembly where multiple exercises need to be fetched efficiently. Results maintain the same order as input IDs when possible.

      Parameters

      • ids: string[]

        Array of unique exercise identifiers to retrieve

      Returns Promise<Exercise[]>

      Promise resolving to array of exercises with complete type-specific data