Skip to content

Commit

Permalink
fix: made requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
corypride committed Jan 10, 2025
1 parent df71e75 commit 6b1f329
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions backend/src/database/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,19 +376,16 @@ func (db *DB) GetTotalCoursesOffered(facilityID *uint) (int, error) {

func (db *DB) GetTotalStudentsEnrolled(facilityID *uint) (int, error) {
var totalStudents int
subQry := db.Table("courses c").
Select("COUNT(DISTINCT m.user_id) AS students_enrolled").
Joins("LEFT JOIN milestones m ON m.course_id = c.id").
Joins("INNER JOIN users u on m.user_id = u.id").
query := db.Table("user_enrollments ue").
Select("COUNT(DISTINCT ue.user_id) AS students_enrolled").
Joins("INNER JOIN users u on ue.user_id = u.id").
Where("u.role = ?", "student")

if facilityID != nil {
subQry = subQry.Where("u.facility_id = ?", facilityID)
query = query.Where("u.facility_id = ?", facilityID)
}

err := db.Table("(?) as sub", subQry).
Select("CASE WHEN SUM(students_enrolled) IS NULL THEN 0 ELSE SUM(students_enrolled) END AS students_enrolled").
Scan(&totalStudents).Error
err := query.Scan(&totalStudents).Error
if err != nil {
return 0, NewDBError(err, "error getting total students enrolled")
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/handlers/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (srv *Server) handleAdminLayer2(w http.ResponseWriter, r *http.Request, log
facility := r.URL.Query().Get("facility")
claims := r.Context().Value(ClaimsKey).(*Claims)
var facilityId *uint

switch facility {
case "all":
facilityId = nil
Expand Down

0 comments on commit 6b1f329

Please sign in to comment.