chore(adresse): improuve adresse data source

This commit is contained in:
Paul Chavard 2023-10-13 16:06:00 +02:00
parent f0168d1470
commit b92ccc0a09
2 changed files with 26 additions and 5 deletions

View file

@ -1,11 +1,33 @@
class DataSources::AdresseController < ApplicationController class DataSources::AdresseController < ApplicationController
def search def search
if params[:q].present? && params[:q].length > 3 if params[:q].present? && params[:q].length > 3
response = Typhoeus.get("#{API_ADRESSE_URL}/search", params: { q: params[:q], limit: 10 }) response = fetch_results
result = JSON.parse(response.body, symbolize_names: true)
render json: result[:features].map { { label: _1[:properties][:label], value: _1[:properties][:label] } } if response.success?
results = JSON.parse(response.body, symbolize_names: true)
render json: format_results(results)
else
render json: []
end
else else
render json: [] render json: []
end end
end end
private
def fetch_results
Typhoeus.get("#{API_ADRESSE_URL}/search", params: { q: params[:q], limit: 10 })
end
def format_results(results)
results[:features].map do
{
label: _1[:properties][:label],
value: _1[:properties][:label],
data: _1[:properties]
}
end
end
end end

View file

@ -596,8 +596,7 @@ class TypeDeChamp < ApplicationRecord
# We should refresh all champs after update except for champs using react or custom refresh # We should refresh all champs after update except for champs using react or custom refresh
# logic (RNA, SIRET, etc.) # logic (RNA, SIRET, etc.)
case type_champ case type_champ
when type_champs.fetch(:address), when type_champs.fetch(:annuaire_education),
type_champs.fetch(:annuaire_education),
type_champs.fetch(:carte), type_champs.fetch(:carte),
type_champs.fetch(:piece_justificative), type_champs.fetch(:piece_justificative),
type_champs.fetch(:titre_identite), type_champs.fetch(:titre_identite),