Null out empty AX values before saving (#131)
This commit is contained in:
parent
5cd357be3f
commit
2dd37d1a1e
1 changed files with 17 additions and 10 deletions
|
|
@ -41,10 +41,10 @@ module Api
|
||||||
weapon = GridWeapon.create!(party_id: party.id, weapon_id: incoming.id,
|
weapon = GridWeapon.create!(party_id: party.id, weapon_id: incoming.id,
|
||||||
position: resolve_params[:position], uncap_level: uncap_level)
|
position: resolve_params[:position], uncap_level: uncap_level)
|
||||||
|
|
||||||
if weapon.save
|
return unless weapon.save
|
||||||
view = render_grid_weapon_view(weapon, resolve_params[:position])
|
|
||||||
render json: view, status: :created
|
view = render_grid_weapon_view(weapon, resolve_params[:position])
|
||||||
end
|
render json: view, status: :created
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
|
@ -56,7 +56,14 @@ module Api
|
||||||
|
|
||||||
# Maybe we make methods on the model to validate for us somehow
|
# Maybe we make methods on the model to validate for us somehow
|
||||||
|
|
||||||
render json: GridWeaponBlueprint.render(@weapon, view: :nested) if @weapon.update(weapon_params)
|
@weapon.assign_attributes(weapon_params)
|
||||||
|
|
||||||
|
@weapon.ax_modifier1 = nil if weapon_params[:ax_modifier1] == -1
|
||||||
|
@weapon.ax_modifier2 = nil if weapon_params[:ax_modifier2] == -1
|
||||||
|
@weapon.ax_strength1 = nil if weapon_params[:ax_strength1].zero?
|
||||||
|
@weapon.ax_strength2 = nil if weapon_params[:ax_strength2].zero?
|
||||||
|
|
||||||
|
render json: GridWeaponBlueprint.render(@weapon, view: :nested) if @weapon.save
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|
@ -121,15 +128,15 @@ module Api
|
||||||
# Render the conflict view as a string
|
# Render the conflict view as a string
|
||||||
def render_conflict_view(conflict_weapon, incoming_weapon, incoming_position)
|
def render_conflict_view(conflict_weapon, incoming_weapon, incoming_position)
|
||||||
ConflictBlueprint.render(nil, view: :weapons,
|
ConflictBlueprint.render(nil, view: :weapons,
|
||||||
conflict_weapon: conflict_weapon,
|
conflict_weapon: conflict_weapon,
|
||||||
incoming_weapon: incoming_weapon,
|
incoming_weapon: incoming_weapon,
|
||||||
incoming_position: incoming_position)
|
incoming_position: incoming_position)
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_grid_weapon_view(grid_weapon, conflict_position)
|
def render_grid_weapon_view(grid_weapon, conflict_position)
|
||||||
GridWeaponBlueprint.render(grid_weapon, view: :full,
|
GridWeaponBlueprint.render(grid_weapon, view: :full,
|
||||||
root: :grid_weapon,
|
root: :grid_weapon,
|
||||||
meta: { replaced: conflict_position })
|
meta: { replaced: conflict_position })
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_weapon(weapon)
|
def save_weapon(weapon)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue