Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 74
Bug: listCourses only counts enrollments for first course on page #1
Copy link
Copy link
Closed
Labels
GrantFox OSSIssue tracked in GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaignCampaign: Official CampaignbugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomerstypescriptTypeScript languageTypeScript language
Description
Activity
Metadata
Metadata
Assignees
Labels
GrantFox OSSIssue tracked in GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaignCampaign: Official CampaignbugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomerstypescriptTypeScript languageTypeScript language
Description
In
src/modules/courses/course.service.ts, thelistCoursesmethod fetches enrollment counts for each course on the page to display in the course catalog. However, the enrollment count query only filters by the first course ID, so all other courses on the page show 0 enrollments.The bug (line 48-51)
The fix
Import
inArrayfromdrizzle-ormand use it instead ofeq:The
inArrayfunction generates a SQLWHERE course_id IN (...)clause that queries all course IDs at once.Impact
On a page with 10 courses, only the first course shows its real enrollment count. All others show
0. This is visible in the course catalog where the "enrolled" count appears incorrect.Files to change
src/modules/courses/course.service.ts— line 1 (addinArrayimport) and line 50 (replaceeqwithinArray)How to verify
GET /api/courses?page=1&limit=10enrolledCount: 5, course 2 showsenrolledCount: 3, course 3 showsenrolledCount: 0Before the fix, only course 1 would show
5, and courses 2 and 3 would both show0.Additional context
The
getCourseDetailmethod (line 114) also has a related TODO:enrolledCount: 0, // TODO: aggregate. That should also be fixed using a similarcount()query, but it's a separate concern from this bug.