From 16a38d141dcf365b72ec689c1446cdbc7e587cfd Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Mon, 13 May 2019 11:04:44 +0200 Subject: [PATCH] Move populating the match below to when the state is changed --- app/controllers/matches_controller.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 322387a..d64c60d 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -13,14 +13,14 @@ class MatchesController < ApplicationController # PATCH/PUT /matches/1 def update new_state = match_params['state'] - if new_state == 'finished' - result = PopulateMatchBelowAndSave.call(match: @match) unless @match.group_match? - unless result.success? - render json: { error: 'Moving Team one stage down failed' }, status: :unprocessable_entity - return - end - end if @match.update(match_params) + if new_state == 'finished' + result = PopulateMatchBelowAndSave.call(match: @match) unless @match.group_match? + unless result.success? + render json: { error: 'Moving Team one stage down failed' }, status: :unprocessable_entity + return + end + end render json: @match else render json: @match.errors, status: :unprocessable_entity