From 86651169e9f4be3a087b7c05cb1c2bfa410efc6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=A4dler?= Date: Sun, 7 Apr 2024 17:24:42 +0200 Subject: [PATCH] Sort group scores correctly in backend --- app/serializers/group_serializer.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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