Merge pull request #10094 from tchak/fix-address-city-name-bis
fix(addresse): lookup for city, departement and region name in local db
This commit is contained in:
commit
b924cfaca5
5 changed files with 36 additions and 3 deletions
|
@ -25,5 +25,29 @@ module Types
|
|||
field :region_code, String, "n° de region", null: true
|
||||
|
||||
field :geometry, Types::GeoJSON, "coordonnées géographique", null: true
|
||||
|
||||
def city_name
|
||||
if object['department_code'].present? && object['city_code'].present?
|
||||
APIGeoService.commune_name(object.fetch('department_code'), object.fetch('city_code'))
|
||||
else
|
||||
object['city_name']
|
||||
end
|
||||
end
|
||||
|
||||
def department_name
|
||||
if object['department_code'].present?
|
||||
APIGeoService.departement_name(object.fetch('department_code'))
|
||||
else
|
||||
object['department_name']
|
||||
end
|
||||
end
|
||||
|
||||
def region_name
|
||||
if object['region_code'].present?
|
||||
APIGeoService.region_name(object.fetch('region_code'))
|
||||
else
|
||||
object['region_name']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -131,7 +131,7 @@ module Types
|
|||
postal_code: object.code_postal.presence || '',
|
||||
city_name: object.localite.presence || '',
|
||||
city_code: object.code_insee_localite.presence || ''
|
||||
}
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
def entreprise
|
||||
|
|
|
@ -41,6 +41,6 @@ class Champs::RNAChamp < Champ
|
|||
postal_code: address["code_postal"],
|
||||
city_name: address["commune"],
|
||||
city_code: address["code_insee"]
|
||||
}
|
||||
}.with_indifferent_access
|
||||
end
|
||||
end
|
||||
|
|
|
@ -106,7 +106,7 @@ class Champs::RNFChamp < Champ
|
|||
department_code: address["departmentCode"],
|
||||
region_name: address["regionName"],
|
||||
region_code: address["regionCode"]
|
||||
}
|
||||
}.with_indifferent_access
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -83,10 +83,17 @@ RSpec.describe Types::DossierType, type: :graphql do
|
|||
expect(data[:dossier][:champs][2][:etablissement][:siret]).to eq dossier.champs_public[2].etablissement.siret
|
||||
expect(data[:dossier][:champs][0][:id]).to eq(data[:dossier][:revision][:champDescriptors][0][:id])
|
||||
|
||||
expect(data[:dossier][:champs][1][:address][:cityName]).to eq('Paris 19e Arrondissement')
|
||||
expect(data[:dossier][:champs][1][:address][:departmentName]).to eq('Paris')
|
||||
expect(data[:dossier][:champs][1][:address][:regionName]).to eq('Île-de-France')
|
||||
|
||||
expect(data[:dossier][:champs][3][:rna][:id]).to eq('W173847273')
|
||||
expect(data[:dossier][:champs][3][:rna][:title]).to eq('CROIX ROUGE')
|
||||
expect(data[:dossier][:champs][3][:rna][:address][:label]).to eq('12 RUE xyz 75512 Paris 14e')
|
||||
expect(data[:dossier][:champs][3][:rna][:address][:streetNumber]).to eq('12')
|
||||
expect(data[:dossier][:champs][3][:rna][:address][:cityName]).to eq('Paris 14e')
|
||||
expect(data[:dossier][:champs][3][:rna][:address][:departmentName]).to eq(nil)
|
||||
expect(data[:dossier][:champs][3][:rna][:address][:regionName]).to eq(nil)
|
||||
end
|
||||
|
||||
context 'when etablissement is in degraded mode' do
|
||||
|
@ -452,6 +459,8 @@ RSpec.describe Types::DossierType, type: :graphql do
|
|||
cityCode
|
||||
streetName
|
||||
streetNumber
|
||||
departmentName
|
||||
regionName
|
||||
}
|
||||
|
||||
fragment RNAChampFragment on RNAChamp {
|
||||
|
|
Loading…
Reference in a new issue