Fix grid character creation

Grid characters were only replacing the character when replacing an existing character, so the mods were persisted. This creates a new GridCharacter every time a replacement happens and destroys the old one.
This commit is contained in:
Justin Edmund 2023-01-22 21:24:00 -08:00
parent 633db43e94
commit bd15d91cdd

View file

@ -21,17 +21,16 @@ module Api
conflict_view = render_conflict_view(conflict_characters, incoming_character, character_params[:position])
render json: conflict_view
else
# Replace the grid character in the position if it is already filled
# Destroy the grid character in the position if it is already filled
if GridCharacter.where(party_id: party.id, position: character_params[:position]).exists?
character = GridCharacter.where(party_id: party.id, position: character_params[:position]).limit(1)[0]
character.character_id = incoming_character.id
# Otherwise, create a new grid character
else
character = GridCharacter.create!(character_params.merge(party_id: party.id,
character_id: incoming_character.id))
character.destroy
end
# Then, create a new grid character
character = GridCharacter.create!(character_params.merge(party_id: party.id,
character_id: incoming_character.id))
if character.save!
grid_character_view = render_grid_character_view(character)
render json: grid_character_view, status: :created