diff --git a/app/serializers/group_serializer.rb b/app/serializers/group_serializer.rb index 1700307..dbdca40 100644 --- a/app/serializers/group_serializer.rb +++ b/app/serializers/group_serializer.rb @@ -2,7 +2,17 @@ class GroupSerializer < ApplicationSerializer attributes :number + attributes :group_scores has_many :matches - has_many :group_scores + + def group_scores + sorted_group_scores = object.group_scores.sort_by do |x| + # sort sorts from smallest to largest, therefore we need to negate the values + [ + -x.group_points, -(x.scored_points - x.received_points), -x.scored_points + ] + end + sorted_group_scores.map { |group_score| GroupScoreSerializer.new(group_score) } + end end