2018-04-05 14:52:29 +02:00
|
|
|
class EtablissementUpdateJob < ApplicationJob
|
|
|
|
queue_as :default
|
|
|
|
|
|
|
|
def perform(dossier, siret)
|
2018-03-19 15:40:39 +01:00
|
|
|
etablissement_attributes = ApiEntrepriseService.get_etablissement_params_for_siret(siret, dossier.procedure_id)
|
2018-04-05 14:52:29 +02:00
|
|
|
|
|
|
|
if etablissement_attributes.present?
|
|
|
|
if dossier.etablissement.present?
|
|
|
|
dossier.etablissement.destroy
|
|
|
|
end
|
|
|
|
etablissement_attributes = ActionController::Parameters.new(etablissement_attributes).permit!
|
|
|
|
etablissement = dossier.build_etablissement(etablissement_attributes)
|
|
|
|
etablissement.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|