Skip to content

[Backend]: Prevent duplicate progress entries and validate completed sections #39

Description

@Jidnyasa-P

Description

The course progress endpoint currently appends a new section entry whenever /completemodule is called.

Repeated requests for the same section can therefore create duplicate progress records. The endpoint also accepts any section ID without checking whether that section belongs to the requested course.

Proposed solution

Update the course completion flow to:

  • Validate that courseId and sectionId are provided.
  • Verify that the course exists.
  • Verify that the supplied section belongs to that course.
  • Confirm that the authenticated student is enrolled.
  • Use an atomic MongoDB update such as $addToSet instead of manually pushing into the progress array.
  • Return a clear response when the section was already completed.
  • Return 404 for a missing course or section.
  • Add backend tests for valid, duplicate, invalid, and unenrolled requests.

Acceptance criteria

  • The same section cannot be added twice to progress.
  • Invalid course IDs are handled safely.
  • Section IDs not belonging to the course are rejected.
  • Unenrolled students cannot update progress.
  • Existing valid completion behaviour remains unchanged.
  • The update is performed atomically.
  • Backend tests cover the main success and failure cases.
  • No frontend changes are required.

Suggested files

backend/controllers/userControllers.js
backend/schemas/enrolledCourseModel.js
backend/routers/userRoutes.js
backend/tests/progress.test.js

Metadata

Metadata

Assignees

Labels

ECSoC26Required label for a PR to be eligible for Sentinel scoringECSoC26-L1Easy difficulty, auto-assigned by Sentinel — 5 points

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions