Move populating the match below to when the state is changed
This commit is contained in:
parent
9b5d4646a8
commit
16a38d141d
|
|
@ -13,14 +13,14 @@ class MatchesController < ApplicationController
|
||||||
# PATCH/PUT /matches/1
|
# PATCH/PUT /matches/1
|
||||||
def update
|
def update
|
||||||
new_state = match_params['state']
|
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 @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
|
render json: @match
|
||||||
else
|
else
|
||||||
render json: @match.errors, status: :unprocessable_entity
|
render json: @match.errors, status: :unprocessable_entity
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue