The variants_to_a method was dead but actually we can use it to make the code simpler

This commit is contained in:
Luis Ramos
2020-03-10 18:40:46 +00:00
parent 2184c7c06b
commit 7585e3d1d6

View File

@@ -149,7 +149,7 @@ module OpenFoodNetwork
receiver = @order_cycle.coordinator
exchange = find_exchange(sender.id, receiver.id, true)
requested_ids = attrs[:variants].select{ |_k, v| v }.keys.map(&:to_i) # Only the ids the user has requested
requested_ids = variants_to_a(attrs[:variants]) # Only the ids the user has requested
existing_ids = exchange.present? ? exchange.variants.pluck(:id) : [] # The ids that already exist
editable_ids = editable_variant_ids_for_incoming_exchange_between(sender, receiver) # The ids we are allowed to add/remove
@@ -166,7 +166,7 @@ module OpenFoodNetwork
receiver = Enterprise.find(attrs[:enterprise_id])
exchange = find_exchange(sender.id, receiver.id, false)
requested_ids = attrs[:variants].select{ |_k, v| v }.keys.map(&:to_i) # Only the ids the user has requested
requested_ids = variants_to_a(attrs[:variants]) # Only the ids the user has requested
existing_ids = exchange.present? ? exchange.variants.pluck(:id) : [] # The ids that already exist
editable_ids = editable_variant_ids_for_outgoing_exchange_between(sender, receiver) # The ids we are allowed to add/remove
@@ -184,7 +184,7 @@ module OpenFoodNetwork
end
def variants_to_a(variants)
variants.select { |_k, v| v }.keys.map(&:to_i).sort
variants.select { |_k, v| v }.keys.map(&:to_i)
end
end
end