demarches-normaliennes/app/models/concerns/rna_champ_association_fetchable_concern.rb

19 lines
485 B
Ruby
Raw Normal View History

module RNAChampAssociationFetchableConcern
extend ActiveSupport::Concern
def fetch_association!(rna)
data = APIEntreprise::RNAAdapter.new(rna, procedure_id).to_params
update!(data: data, value: rna)
nil
rescue APIEntreprise::API::Error, ActiveRecord::RecordInvalid => error
self.data = nil
self.value = rna
save(validate: false)
if error.try(:network_error?) && !APIEntrepriseService.api_up?
:network_error
else
nil
end
end
end