fix(adress): show postal code on municipalities
This commit is contained in:
parent
9280ccc23d
commit
5da1eb3024
2 changed files with 14 additions and 1 deletions
|
@ -22,7 +22,16 @@ class DataSources::AdresseController < ApplicationController
|
|||
end
|
||||
|
||||
def format_results(results)
|
||||
results[:features].map do
|
||||
results[:features].flat_map do |feature|
|
||||
if feature[:properties][:type] == 'municipality'
|
||||
departement_code = feature[:properties][:context].split(',').first
|
||||
APIGeoService.commune_postal_codes(departement_code, feature[:properties][:citycode]).map do |postcode|
|
||||
feature.deep_merge(properties: { postcode:, label: "#{feature[:properties][:label]} (#{postcode})" })
|
||||
end
|
||||
else
|
||||
feature
|
||||
end
|
||||
end.map do
|
||||
{
|
||||
label: _1[:properties][:label],
|
||||
value: _1[:properties][:label],
|
||||
|
|
|
@ -81,6 +81,10 @@ class APIGeoService
|
|||
communes(departement_code).find { _1[:name] == name }&.dig(:code)
|
||||
end
|
||||
|
||||
def commune_postal_codes(departement_code, code)
|
||||
communes(departement_code).filter { _1[:code] == code }.map { _1[:postal_code] }
|
||||
end
|
||||
|
||||
def parse_ban_address(feature)
|
||||
return unless ban_address_schema.valid?(feature)
|
||||
|
||||
|
|
Loading…
Reference in a new issue