first try
This commit is contained in:
parent
c895e4e8f6
commit
97280df139
|
|
@ -13,27 +13,29 @@ 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' && @match.current_leading_team.nil?
|
|
||||||
render json: { error: 'Stopping undecided Matches isn\'t allowed in playoff stage' },
|
|
||||||
status: :unprocessable_entity
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if @match.update(match_params)
|
|
||||||
if new_state == 'finished'
|
if new_state == 'finished'
|
||||||
result = PopulateMatchBelowAndSave.call(match: @match) unless @match.group_match?
|
if @match.current_leading_team.nil? # TODO: handle group matches differently
|
||||||
unless result.success?
|
return render_unprocessable_entity(error: 'Stopping undecided Matches isn\'t allowed in playoff stage')
|
||||||
render json: { error: 'Moving Team one stage down failed' }, status: :unprocessable_entity
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
render json: @match
|
unless @match.group_match?
|
||||||
else
|
result = PopulateMatchBelowAndSave.call(match: @match)
|
||||||
render json: @match.errors, status: :unprocessable_entity
|
return render_unprocessable_entity(error: 'Moving Team one stage down failed') unless result.success?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return render json: @match if @match.update(match_params)
|
||||||
|
|
||||||
|
render_unprocessable_entity(@match.errors)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def render_unprocessable_entity(error_message)
|
||||||
|
render json: error_message, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
|
||||||
def validate_params
|
def validate_params
|
||||||
case match_params['state']
|
case match_params['state']
|
||||||
when 'in_progress'
|
when 'in_progress'
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ class PlayoffStageService
|
||||||
|
|
||||||
def get_winners_of(companion_match, current_match)
|
def get_winners_of(companion_match, current_match)
|
||||||
matches = [current_match, companion_match].sort_by(&:position)
|
matches = [current_match, companion_match].sort_by(&:position)
|
||||||
matches.map(&:winner)
|
matches.map(&:current_leading_team)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue