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

    Class CourseRepository

    Course repository class providing comprehensive data access operations for course management. Implements standardized CRUD operations with advanced querying, filtering, and pagination capabilities.

    Index

    Constructors

    Methods

    • Creates a new course in the database with automatic field mapping and validation. Transforms DTO field names to match database schema and applies default values.

      Parameters

      • data: CreateCourseDto & { id: string }

        Course creation data with all required fields

        • id

          Unique identifier for the course

        • source_language

          Source language code (e.g., 'en', 'es')

        • target_language

          Target language code (e.g., 'en', 'es')

        • name

          Display name of the course

        • description

          Optional detailed description of the course

        • is_public

          Whether the course is publicly accessible (defaults to true)

        • id: string

          Unique identifier for the course

      Returns Promise<Course>

      Promise resolving to the created course with transformed field names

      When database operation fails or constraint violations occur

    • Retrieves a single course by its unique identifier with level count information. Includes relationship counting for associated levels to provide comprehensive course data.

      Parameters

      • id: string

        Unique identifier of the course to retrieve

      Returns Promise<null | Course & { levels_count: number }>

      Promise resolving to course with level count or null if not found

    • Retrieves a paginated list of courses with advanced filtering, searching, and sorting capabilities. Supports text search across course names and descriptions, boolean filtering for public/private courses, and comprehensive sorting options with level count information included for each course.

      Parameters

      • Optionaloptions: QueryOptions = {}

        Query configuration options for filtering, pagination, and sorting

        • page

          Page number for pagination (1-based)

        • limit

          Maximum number of courses per page

        • search

          Text search query applied to course names and descriptions

        • filters

          Filter conditions (supports 'is_public' boolean filter)

        • sortBy

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

        • sortOrder

          Sort direction

      Returns Promise<PaginatedResult<Course & { levels_count: number }>>

      Promise resolving to paginated course results with level counts

    • Updates an existing course with partial data and field mapping transformation. Supports updating any combination of course fields with proper null/undefined handling for optional fields like description.

      Parameters

      • id: string

        Unique identifier of the course to update

      • data: Partial<CreateCourseDto>

        Partial course data with fields to update

        • source_language

          Updated source language code

        • target_language

          Updated target language code

        • name

          Updated course name

        • description

          Updated description (undefined to remove)

        • is_public

          Updated public visibility status

      Returns Promise<Course & { levels_count: number }>

      Promise resolving to updated course with level count

      When course is not found or database operation fails

    • Deletes a course from the database by its unique identifier. Handles deletion gracefully with error catching to prevent application crashes.

      Parameters

      • id: string

        Unique identifier of the course to delete

      Returns Promise<boolean>

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

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

      Parameters

      • id: string

        Unique identifier of the course to check

      Returns Promise<boolean>

      Promise resolving to true if course exists, false otherwise