Skip to content

Fix enrollment count query to include all courses on page, not just the first#53

Merged
DeFiVC merged 1 commit into
ChainLearnOfficial:mainfrom
Levi-Ojukwu:main
Jun 24, 2026
Merged

Fix enrollment count query to include all courses on page, not just the first#53
DeFiVC merged 1 commit into
ChainLearnOfficial:mainfrom
Levi-Ojukwu:main

Conversation

@Levi-Ojukwu

Copy link
Copy Markdown
Contributor

Summary

Fix enrolledCount in course listings returning 0 for every course except the first one on the page.

Problem

In CourseService.listCourses, the enrollment count query used eq(enrollments.courseId, courseIds[0]) which only filtered for the first course ID. All other courses on the page received an enrollment count of 0.

Fix

Replaced eq(enrollments.courseId, courseIds[0]) with inArray(enrollments.courseId, courseIds) so the query fetches enrollment counts for all courses on the current page in a single query.
File changed: src/modules/courses/course.service.ts — added inArray import and updated the .where() clause.

Closes #26

@DeFiVC DeFiVC left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review: Fix enrollment count query to include all courses on page

Author: Levi-Ojukwu (Ojukwu_Levi) | Closes: #26 | State: OPEN | Mergeable: MERGEABLE

Review Checklist

Item Status
Git Identity ✅ DeFiVC defivc1@email.com
Linked Issue ✅ Closes #26 — matches requirements exactly
Code Quality ✅ Correct and minimal fix
CI Status ✅ Lint & Typecheck: SUCCESS, Test: SUCCESS
Merge Conflicts ✅ None

Code Analysis

src/modules/courses/course.service.ts (2 additions, 2 deletions):

  1. Line 1: Added inArray to the drizzle-orm import — correct
  2. Line 50: Changed eq(enrollments.courseId, courseIds[0]) to inArray(enrollments.courseId, courseIds) — correct

This is a clean, minimal fix that exactly addresses the issue. The original code was filtering enrollments using only the first course ID in the array, causing all other courses to show an enrollment count of 0. The fix uses inArray to query for all course IDs on the current page in a single query.

Decision: APPROVE

The PR is a correct, minimal bug fix that exactly matches the issue requirements. CI is green, no merge conflicts. This is ready to merge.

@DeFiVC DeFiVC merged commit 5b1963f into ChainLearnOfficial:main Jun 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[HIGH] Enrollment count only queries first course on page

2 participants