From d71aabd29144abcf643377651e79dee7128501a3 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 5 Apr 2018 14:52:29 +0200 Subject: [PATCH] Job to fetch missing etablissement --- app/jobs/etablissement_update_job.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 app/jobs/etablissement_update_job.rb diff --git a/app/jobs/etablissement_update_job.rb b/app/jobs/etablissement_update_job.rb new file mode 100644 index 000000000..10566f8cf --- /dev/null +++ b/app/jobs/etablissement_update_job.rb @@ -0,0 +1,19 @@ +class EtablissementUpdateJob < ApplicationJob + queue_as :default + + def perform(dossier, siret) + etablissement_attributes = SIRETService.fetch(siret, dossier.procedure_id, dossier) + + if etablissement_attributes.present? + if dossier.entreprise.present? + dossier.entreprise.destroy + end + 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