Sort group scores correctly in backend

This commit is contained in:
Daniel Schädler 2024-04-07 17:24:42 +02:00
parent 914584dba4
commit 86651169e9
1 changed files with 11 additions and 1 deletions

View File

@ -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