fix(epci): do not show let select departements with no epci

This commit is contained in:
Paul Chavard 2023-10-23 10:31:52 +02:00
parent a6842e8484
commit 045b4942d9
7 changed files with 16 additions and 3 deletions

View file

@ -8,7 +8,7 @@ class EditableChamp::EpciComponent < EditableChamp::EditableChampBaseComponent
private
def departement_options
APIGeoService.departements.filter { _1[:code] != '99' }.map { ["#{_1[:code]} #{_1[:name]}", _1[:code]] }
APIGeoService.departements.filter(&method(:departement_with_epci?)).map { ["#{_1[:code]} #{_1[:name]}", _1[:code]] }
end
def epci_options
@ -26,4 +26,9 @@ class EditableChamp::EpciComponent < EditableChamp::EditableChampBaseComponent
def epci_select_options
{ selected: @champ.code }.merge(@champ.mandatory? ? { prompt: '' } : { include_blank: '' })
end
def departement_with_epci?(departement)
code = departement[:code]
!code.start_with?('98') && !code.in?(['99', '975', '977', '978'])
end
end

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1 @@
[]

View file

@ -10,8 +10,11 @@ namespace :api_geo_data do
departements = get_from_api_geo('departements?zone=metro,drom,com', 'departements')
departements.each do |departement|
departement_code = departement[:code]
if !departement_code.start_with?('98')
get_from_api_geo("epcis?codeDepartement=#{departement_code}", "epcis-#{departement_code}")
epci_filename = "epcis-#{departement_code}"
if departement_code.start_with?('98')
PATH.join("#{epci_filename}.json").write(JSON.dump([]))
else
get_from_api_geo("epcis?codeDepartement=#{departement_code}", epci_filename)
end
get_from_api_geo("communes?codeDepartement=#{departement_code}&type=commune-actuelle,arrondissement-municipal", "communes-#{departement_code}")
end