Overview
The UserActivity model tracks user engagement with classes and tasks. It creates records when users participate in virtual classes and complete learning activities, providing a comprehensive view of their learning progress.UserActivity Model
The UserActivity model serves as a junction table that connects users with their tasks and classes, tracking completion status and role assignments.Model Structure
Unique identifier for the activity record (MongoDB ObjectId)
Reference to the User who performed the activity
Reference to the Task being completed (optional - can be null for class-only activities)
Reference to the VirtualClass associated with this activity
User’s role in the class. Possible values:
anfitrion- Host/organizer of the classparticipante- Participant in the class
Indicates whether the activity/task has been completed. Defaults to
falseTimestamp when the activity record was created
Timestamp when the activity record was last updated
Activity Creation
UserActivity records are automatically created in the following scenarios:1. Class Host Registration
When a user books a new class, they are registered as the host (anfitrion):
2. Class Participant Registration
When a user joins an existing class as a participant:Task Completion Flow
Get User Activity for a Task
Retrieves the activity record for a specific task:Mark Task as Complete
Updates the activity record to mark it as completed:Complete Task and Increment Class Counter
When a task is marked complete, the user’s total class count is automatically incremented:Response Examples
UserActivity Record
Multiple Activities Query
Related Models
User Model Fields
Total number of completed classes for the user (automatically incremented when tasks are completed)
Array of all UserActivity records associated with the user
Task Model
Tasks represent learning activities that users can complete:Unique task identifier
Task title
Markdown content for the task (AI-generated)
Markdown answer/solution (AI-generated)
Short description of the task
Task type:
exam, audio, video, or readingDifficulty level:
easy, medium, or hardVirtualClass Model
Virtual classes are linked to user activities:User ID of the class organizer (host)
Array of user IDs for all participants in the class
Current number of participants
Maximum allowed participants
Type of class:
individual or grupal (group)Class status:
scheduled, pending, completed, or cancelledCommon Queries
Get All Activities for a User
Get Completed Activities
Get Activities by Role
Best Practices
- Activity Creation: Always create a UserActivity record when a user joins or hosts a class
- Completion Tracking: Mark activities as completed only after the user has finished the associated task
- Role Assignment: Ensure the correct role (
anfitrionorparticipante) is assigned based on the user’s participation type - Total Classes: The
totalClassescounter on the User model is incremented automatically when tasks are completed - do not modify it manually - Null Tasks: Activities can have
taskIdset tonullfor class participation without specific task assignments