feat(rna): also store rna title
This commit is contained in:
parent
a9237bf7f1
commit
cfd568b98d
5 changed files with 17 additions and 4 deletions
|
@ -13,6 +13,10 @@ class Champs::RNAChamp < Champ
|
|||
data&.dig("association_titre")
|
||||
end
|
||||
|
||||
def update_with_external_data!(data:)
|
||||
update!(data:, value_json: extract_value_json(data:))
|
||||
end
|
||||
|
||||
def identifier
|
||||
title.present? ? "#{value} (#{title})" : value
|
||||
end
|
||||
|
@ -41,4 +45,11 @@ class Champs::RNAChamp < Champ
|
|||
city_code: address["code_insee"]
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def extract_value_json(data:)
|
||||
h = APIGeoService.parse_rna_address(data['adresse'])
|
||||
h.merge(title: data['association_titre'])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ module RNAChampAssociationFetchableConcern
|
|||
return clear_association!(:invalid) unless valid_champ_value?
|
||||
return clear_association!(:not_found) if (data = APIEntreprise::RNAAdapter.new(rna, procedure_id).to_params).blank?
|
||||
|
||||
update!(data:, value_json: APIGeoService.parse_rna_address(data['adresse']))
|
||||
update_with_external_data!(data:)
|
||||
rescue APIEntreprise::API::Error, APIEntrepriseToken::TokenError => error
|
||||
if APIEntrepriseService.service_unavailable_error?(error, target: :djepva)
|
||||
clear_association!(:network_error)
|
||||
|
|
|
@ -14,7 +14,7 @@ module Maintenance
|
|||
return if champ&.dossier&.procedure&.id.blank?
|
||||
data = APIEntreprise::RNAAdapter.new(champ.value, champ&.dossier&.procedure&.id).to_params
|
||||
return if data.blank?
|
||||
champ.update(value_json: APIGeoService.parse_rna_address(data['adresse']))
|
||||
champ.update_with_external_data!(data:)
|
||||
rescue URI::InvalidURIError
|
||||
# some Champs::RNAChamp contain spaces which raise this error
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
|
|
|
@ -134,7 +134,8 @@ describe Champs::RNAController, type: :controller do
|
|||
"region_name" => nil,
|
||||
"street_address" => "33 rue de Modagor",
|
||||
"street_name" => "de Modagor",
|
||||
"street_number" => "33"
|
||||
"street_number" => "33",
|
||||
"title" => "LA PRÉVENTION ROUTIERE"
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,7 +33,8 @@ module Maintenance
|
|||
"departement_name" => nil,
|
||||
"department_name" => nil,
|
||||
"region_code" => nil,
|
||||
"region_name" => nil
|
||||
"region_name" => nil,
|
||||
"title" => "LA PRÉVENTION ROUTIERE"
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue