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

    Class ProgressService

    Progress tracking and gamification service for managing user learning progress.

    ProgressService

    Index

    Constructors

    Methods

    • Retrieves user progress data, automatically creating initial progress record if none exists.

      This method ensures every user has a progress record by creating one with default values (0 experience points, 5 lives, 0 streak) when no existing progress is found.

      Parameters

      • userId: string

        The unique identifier of the user

      Returns Promise<UserProgress>

      Promise resolving to the user's progress data

      const progress = await progressService.getUserProgress('user-123');
      console.log(`User has ${progress.experience_points} experience points`);
    • Updates specific fields of a user's progress record.

      Parameters

      • userId: string

        The unique identifier of the user

      • updates: UpdateUserProgressDto

        Object containing the fields to update

      Returns Promise<UserProgress>

      Promise resolving to the updated progress data

      When user progress is not found (404 NOT_FOUND)

    • Processes lesson completion, calculates experience points, and updates user progress.

      This method handles the complete lesson completion workflow including duplicate prevention, experience calculation based on performance, streak updates, and progress tracking. Experience points are calculated using the lesson's base points with performance multipliers:

      • 90+ score: 20% bonus
      • 80-89 score: 10% bonus
      • 60-79 score: no modifier
      • <60 score: 20% reduction

      Parameters

      • userId: string

        The unique identifier of the user

      • progressData: UpdateProgressDto

        Lesson completion data including lesson_id, score, and time_spent

      Returns Promise<
          {
              progress: UserProgress;
              completion: LessonCompletion;
              experienceGained: number;
          },
      >

      Promise resolving to updated progress, completion record, and experience points gained

      When lesson is already completed (409 CONFLICT) or lesson not found (404 NOT_FOUND)

    • Synchronizes offline lesson completions with the server, handling conflicts and duplicates.

      This method processes multiple lesson completions from offline usage, automatically detecting and skipping duplicates while maintaining data integrity. Completions are processed in chronological order and experience points are accumulated and applied in a single update.

      Parameters

      • userId: string

        The unique identifier of the user

      • syncData: OfflineProgressSync

        Offline sync data containing completions and last sync timestamp

      Returns Promise<
          {
              synced_completions: number;
              skipped_duplicates: number;
              updated_progress: UserProgress;
          },
      >

      Promise resolving to sync statistics and updated progress

    • Retrieves comprehensive progress summary including lessons and courses statistics.

      Parameters

      • userId: string

        The unique identifier of the user

      Returns Promise<ProgressSummary>

      Promise resolving to detailed progress summary

    • Retrieves paginated list of user's lesson completions with sorting options.

      Parameters

      • userId: string

        The unique identifier of the user

      • Optionaloptions: QueryOptions = {}

        Optional pagination and sorting parameters

      Returns Promise<PaginatedResult<LessonCompletion>>

      Promise resolving to paginated completion results

    • Checks whether a specific lesson has been completed by the user.

      Parameters

      • userId: string

        The unique identifier of the user

      • lessonId: string

        The unique identifier of the lesson

      Returns Promise<boolean>

      Promise resolving to true if lesson is completed, false otherwise

    • Retrieves aggregated completion statistics for a specific lesson (analytics function).

      Parameters

      • lessonId: string

        The unique identifier of the lesson

      Returns Promise<
          {
              total_completions: number;
              average_score: null
              | number;
              average_time_spent: null | number;
          },
      >

      Promise resolving to lesson completion statistics

    • Resets user progress to initial state (administrative function).

      This method resets experience points to 0, lives to 5, streak to 0, and clears the last completed lesson.

      Parameters

      • userId: string

        The unique identifier of the user

      Returns Promise<UserProgress>

      Promise resolving to the reset progress data

    • Awards bonus experience points to a user for special achievements or events.

      Parameters

      • userId: string

        The unique identifier of the user

      • bonusPoints: number

        The number of bonus experience points to award

      • reason: string

        Description of why the bonus was awarded (for logging)

      Returns Promise<UserProgress>

      Promise resolving to the updated progress data

    • Updates user's current lives count for gamification features.

      Lives are clamped between 0 and 10 to maintain game balance.

      Parameters

      • userId: string

        The unique identifier of the user

      • livesChange: number

        The change in lives (positive to add, negative to subtract)

      Returns Promise<UserProgress>

      Promise resolving to the updated progress data