Reduce method calls

This commit is contained in:
gregoirenovel 2018-03-19 14:46:47 +01:00
parent 8b46df3176
commit b479833699

View file

@ -6,13 +6,13 @@ class SIRETService
entreprise_params = ApiEntreprise::EntrepriseAdapter.new(siren(siret), procedure_id).to_params
if etablissement_params.present? && entreprise_params.present?
association = ApiEntreprise::RNAAdapter.new(siret, procedure_id)
exercices = ApiEntreprise::ExercicesAdapter.new(siret, procedure_id)
association_params = ApiEntreprise::RNAAdapter.new(siret, procedure_id).to_params
exercices_array = ApiEntreprise::ExercicesAdapter.new(siret, procedure_id).to_array
params = etablissement_params
.merge(entreprise_params.map { |k,v| ["entreprise_#{k}", v] }.to_h)
.merge(association.to_params&.map { |k,v| ["association_#{k}", v] }.to_h)
.merge(exercices_attributes: exercices.to_array)
.merge(association_params&.map { |k,v| ["association_#{k}", v] }.to_h)
.merge(exercices_attributes: exercices_array)
# This is to fill legacy models and relationships
if dossier.present?
@ -20,7 +20,7 @@ class SIRETService
entreprise_attributes: entreprise_params
.merge({
dossier: dossier,
rna_information_attributes: association.to_params
rna_information_attributes: association_params
}.compact)
)
else