Skip to content

Commit

Permalink
fix: 500 error if paginated_stats are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
adeel.tajamul committed Nov 21, 2023
1 parent f408aa2 commit f94ffaa
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions api/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,19 @@
]
}}
]).to_a[0]
total_count = paginated_stats["pagination"][0]["total_count"]
num_pages = [1, (total_count / per_page.to_f).ceil].max
data = paginated_stats["data"].map do |user_stats|
{
:username => user_stats["username"]
}.merge(user_stats["course_stats"].except(*exclude_from_stats))
if paginated_stats["pagination"].empty?
data = []
num_pages = 0
page = 0
total_count = 0

Check warning on line 78 in api/users.rb

View check run for this annotation

Codecov / codecov/patch

api/users.rb#L75-L78

Added lines #L75 - L78 were not covered by tests
else
total_count = paginated_stats["pagination"][0]["total_count"]
num_pages = [1, (total_count / per_page.to_f).ceil].max
data = paginated_stats["data"].map do |user_stats|
{
:username => user_stats["username"]
}.merge(user_stats["course_stats"].except(*exclude_from_stats))
end
end
else
# If a list of usernames is provided, then sort by the order in which those names appear
Expand Down

0 comments on commit f94ffaa

Please sign in to comment.