2018-02-22 16:53:29 +01:00
|
|
|
class SIRETService
|
|
|
|
def self.fetch(siret, dossier = nil)
|
2018-03-19 14:44:47 +01:00
|
|
|
procedure_id = dossier&.procedure_id
|
|
|
|
|
|
|
|
etablissement_params = ApiEntreprise::EtablissementAdapter.new(siret, procedure_id).to_params
|
2018-03-29 12:15:33 +02:00
|
|
|
entreprise_params = ApiEntreprise::EntrepriseAdapter.new(siret, procedure_id).to_params
|
2018-02-22 16:53:29 +01:00
|
|
|
|
2018-03-19 14:48:15 +01:00
|
|
|
if etablissement_params.present? && entreprise_params.present?
|
2018-03-19 14:46:47 +01:00
|
|
|
association_params = ApiEntreprise::RNAAdapter.new(siret, procedure_id).to_params
|
2018-03-19 15:43:15 +01:00
|
|
|
exercices_params = ApiEntreprise::ExercicesAdapter.new(siret, procedure_id).to_params
|
2018-02-22 16:53:29 +01:00
|
|
|
|
2018-03-19 14:48:15 +01:00
|
|
|
params = etablissement_params
|
2018-03-19 15:36:39 +01:00
|
|
|
.merge(entreprise_params.transform_keys { |k| "entreprise_#{k}" })
|
2018-03-19 14:47:56 +01:00
|
|
|
.merge(association_params.transform_keys { |k| "association_#{k}" })
|
2018-03-19 15:43:15 +01:00
|
|
|
.merge(exercices_params)
|
2018-02-22 16:53:29 +01:00
|
|
|
|
|
|
|
# This is to fill legacy models and relationships
|
|
|
|
if dossier.present?
|
2018-03-19 15:30:44 +01:00
|
|
|
handle_legacy_models!(params, entreprise_params, dossier, association_params)
|
2018-02-22 16:53:29 +01:00
|
|
|
end
|
2018-03-19 15:27:12 +01:00
|
|
|
|
|
|
|
params
|
2018-02-22 16:53:29 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-19 15:30:44 +01:00
|
|
|
def self.handle_legacy_models!(params, entreprise_params, dossier, association_params)
|
|
|
|
params[:entreprise_attributes] = entreprise_params.merge(
|
|
|
|
{
|
|
|
|
dossier: dossier,
|
|
|
|
rna_information_attributes: association_params.presence
|
|
|
|
}.compact
|
|
|
|
)
|
|
|
|
end
|
2018-02-22 16:53:29 +01:00
|
|
|
end
|