From eb141b59b50f804b4efdce991ab323cb8d0d4c9b Mon Sep 17 00:00:00 2001 From: IzStriker <44909896+IzStriker@users.noreply.github.com> Date: Fri, 24 May 2024 16:45:10 +0100 Subject: [PATCH] fix: stage selection (#744) Fixes #728 --- backend/bracket/sql/stages.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/bracket/sql/stages.py b/backend/bracket/sql/stages.py index b86ab2bb..e6d05e1b 100644 --- a/backend/bracket/sql/stages.py +++ b/backend/bracket/sql/stages.py @@ -158,7 +158,7 @@ async def get_next_stage_in_tournament( THEN ( id > COALESCE( ( - SELECT id FROM stages AS t + SELECT id FROM stages WHERE is_active IS TRUE AND stages.tournament_id = :tournament_id ORDER BY id ASC @@ -170,7 +170,7 @@ async def get_next_stage_in_tournament( ELSE ( id < COALESCE( ( - SELECT id FROM stages AS t + SELECT id FROM stages WHERE is_active IS TRUE AND stages.tournament_id = :tournament_id ORDER BY id DESC @@ -182,6 +182,9 @@ async def get_next_stage_in_tournament( END AND stages.tournament_id = :tournament_id AND is_active IS FALSE + ORDER BY + CASE WHEN :direction='next' THEN id END ASC, + CASE WHEN NOT :direction='next' THEN id END DESC """ return cast( StageId | None,