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
Suggested files
backend/controllers/userControllers.js
backend/schemas/enrolledCourseModel.js
backend/routers/userRoutes.js
backend/tests/progress.test.js
Description
The course progress endpoint currently appends a new section entry whenever
/completemoduleis 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:
courseIdandsectionIdare provided.$addToSetinstead of manually pushing into the progress array.404for a missing course or section.Acceptance criteria
Suggested files