diff --git a/app/controllers/api/v1/grid_summons_controller.rb b/app/controllers/api/v1/grid_summons_controller.rb index 788f3d5..9d5f32e 100644 --- a/app/controllers/api/v1/grid_summons_controller.rb +++ b/app/controllers/api/v1/grid_summons_controller.rb @@ -16,10 +16,8 @@ module Api summon.attributes = summon_params.merge(party_id: party.id, summon_id: incoming_summon.id) if summon.validate - ap 'Validating' save_summon(summon) else - ap 'Handling conflict' handle_conflict(summon) end end @@ -48,6 +46,7 @@ module Api def handle_conflict(summon) conflict_summon = summon.conflicts(party) + ap conflict_summon return unless conflict_summon.summon.id == incoming_summon.id old_position = conflict_summon.position @@ -91,8 +90,8 @@ module Api def render_grid_summon_view(grid_summon, conflict_position = nil) GridSummonBlueprint.render(grid_summon, view: :nested, - root: :grid_summon, - meta: { replaced: conflict_position }) + root: :grid_summon, + meta: { replaced: conflict_position }) end def set diff --git a/app/models/grid_summon.rb b/app/models/grid_summon.rb index 7da4930..f539424 100644 --- a/app/models/grid_summon.rb +++ b/app/models/grid_summon.rb @@ -21,13 +21,9 @@ class GridSummon < ApplicationRecord def conflicts(party) return unless summon.limit - party.summons.find do |party_summon| - ap 'Normal summon:' - ap summon - ap 'Party summon:' - ap party_summon - - summon if summon.id == party_summon.summon.id + party.summons.find do |grid_summon| + return unless grid_summon.id + grid_summon if summon.id == grid_summon.summon.id end end @@ -35,15 +31,12 @@ class GridSummon < ApplicationRecord # Validates whether there is a conflict with the party def no_conflicts - ap conflicts(party) - - # Check if the grid weapon conflicts with any of the other grid weapons in the party + # Check if the grid summon conflicts with any of the other grid summons in the party errors.add(:series, 'must not conflict with existing summons') unless conflicts(party).nil? end - # Validates whether the weapon can be added to the desired position + # Validates whether the summon can be added to the desired position def compatible_with_position - ap [4, 5].include?(position.to_i) && !summon.subaura return unless [4, 5].include?(position.to_i) && !summon.subaura errors.add(:position, 'must have subaura for position')