demarches-normaliennes/app/models/concerns/rna_champ_association_fetchable_concern.rb
sebastiencarceles 33fa40eda2 don't clean the rna champ value
Cleaning the value is useless, when fetching the association,
as the value will be re-written by the dossier update, when the user
fills in the dossier.

Furthermore we need the value to persist when prefilling the champ.
2023-02-27 14:35:11 +01:00

18 lines
485 B
Ruby

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