chore(adresse): improuve adresse data source
This commit is contained in:
parent
f0168d1470
commit
b92ccc0a09
2 changed files with 26 additions and 5 deletions
|
@ -1,11 +1,33 @@
|
|||
class DataSources::AdresseController < ApplicationController
|
||||
def search
|
||||
if params[:q].present? && params[:q].length > 3
|
||||
response = Typhoeus.get("#{API_ADRESSE_URL}/search", params: { q: params[:q], limit: 10 })
|
||||
result = JSON.parse(response.body, symbolize_names: true)
|
||||
render json: result[:features].map { { label: _1[:properties][:label], value: _1[:properties][:label] } }
|
||||
response = fetch_results
|
||||
|
||||
if response.success?
|
||||
results = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
render json: format_results(results)
|
||||
else
|
||||
render json: []
|
||||
end
|
||||
else
|
||||
render json: []
|
||||
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
|
||||
|
|
|
@ -596,8 +596,7 @@ class TypeDeChamp < ApplicationRecord
|
|||
# We should refresh all champs after update except for champs using react or custom refresh
|
||||
# logic (RNA, SIRET, etc.)
|
||||
case type_champ
|
||||
when type_champs.fetch(:address),
|
||||
type_champs.fetch(:annuaire_education),
|
||||
when type_champs.fetch(:annuaire_education),
|
||||
type_champs.fetch(:carte),
|
||||
type_champs.fetch(:piece_justificative),
|
||||
type_champs.fetch(:titre_identite),
|
||||
|
|
Loading…
Reference in a new issue