2018-04-10 12:24:49 +02:00
|
|
|
class ApiEntrepriseService
|
2020-05-15 17:15:52 +02:00
|
|
|
# create etablissement with EtablissementAdapter
|
|
|
|
# enqueue api_entreprise jobs to retrieve
|
|
|
|
# all informations we can get about a SIRET.
|
2019-04-30 16:36:40 +02:00
|
|
|
#
|
2020-05-15 17:15:52 +02:00
|
|
|
# Returns nil if the SIRET is unknown
|
2019-04-30 16:36:40 +02:00
|
|
|
#
|
2020-12-03 16:52:58 +01:00
|
|
|
# Raises a ApiEntreprise::API::Error::RequestFailed exception on transient errors
|
2019-04-30 16:36:40 +02:00
|
|
|
# (timeout, 5XX HTTP error code, etc.)
|
2020-05-26 17:55:45 +02:00
|
|
|
def self.create_etablissement(dossier_or_champ, siret, user_id = nil)
|
|
|
|
etablissement_params = ApiEntreprise::EtablissementAdapter.new(siret, dossier_or_champ.procedure.id).to_params
|
2020-05-15 17:15:52 +02:00
|
|
|
return nil if etablissement_params.empty?
|
|
|
|
|
2020-05-26 17:55:45 +02:00
|
|
|
etablissement = dossier_or_champ.build_etablissement(etablissement_params)
|
2020-08-13 11:53:32 +02:00
|
|
|
etablissement.save!
|
2020-05-15 17:15:52 +02:00
|
|
|
|
|
|
|
[
|
|
|
|
ApiEntreprise::EntrepriseJob, ApiEntreprise::AssociationJob, ApiEntreprise::ExercicesJob,
|
|
|
|
ApiEntreprise::EffectifsJob, ApiEntreprise::EffectifsAnnuelsJob, ApiEntreprise::AttestationSocialeJob,
|
|
|
|
ApiEntreprise::BilansBdfJob
|
|
|
|
].each do |job|
|
2020-05-26 17:55:45 +02:00
|
|
|
job.perform_later(etablissement.id, dossier_or_champ.procedure.id)
|
2018-02-22 16:53:29 +01:00
|
|
|
end
|
2020-05-26 17:55:45 +02:00
|
|
|
ApiEntreprise::AttestationFiscaleJob.perform_later(etablissement.id, dossier_or_champ.procedure.id, user_id)
|
2020-04-07 19:29:14 +02:00
|
|
|
|
2020-05-15 17:15:52 +02:00
|
|
|
etablissement
|
2020-04-07 19:29:14 +02:00
|
|
|
end
|
2018-02-22 16:53:29 +01:00
|
|
|
end
|