Merge pull request #9751 from tchak/departement-tags
feat(champs): expose more tags and api fields on rnf, address and commune
This commit is contained in:
commit
29df9ad09d
10 changed files with 158 additions and 36 deletions
|
@ -573,6 +573,12 @@ class API::V2::StoredQuery
|
||||||
rnf {
|
rnf {
|
||||||
...RNFFragment
|
...RNFFragment
|
||||||
}
|
}
|
||||||
|
commune {
|
||||||
|
...CommuneFragment
|
||||||
|
}
|
||||||
|
departement {
|
||||||
|
...DepartementFragment
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3626,6 +3626,8 @@ type RNF {
|
||||||
}
|
}
|
||||||
|
|
||||||
type RNFChamp implements Champ {
|
type RNFChamp implements Champ {
|
||||||
|
commune: Commune
|
||||||
|
departement: Departement
|
||||||
id: ID!
|
id: ID!
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -3,40 +3,14 @@ module Types::Champs
|
||||||
implements Types::ChampType
|
implements Types::ChampType
|
||||||
|
|
||||||
class RNFType < Types::BaseObject
|
class RNFType < Types::BaseObject
|
||||||
field :id, String, null: false
|
field :id, String, null: false, method: :external_id
|
||||||
field :title, String, null: true
|
field :title, String, null: true, method: :title
|
||||||
field :address, Types::AddressType, null: true
|
field :address, Types::AddressType, null: true, method: :rnf_address
|
||||||
|
|
||||||
def id
|
|
||||||
object.value
|
|
||||||
end
|
|
||||||
|
|
||||||
def title
|
|
||||||
object.data["title"]
|
|
||||||
end
|
|
||||||
|
|
||||||
def address
|
|
||||||
address = object.data["address"]
|
|
||||||
if address
|
|
||||||
{
|
|
||||||
label: address["label"],
|
|
||||||
type: address["type"],
|
|
||||||
street_address: address["streetAddress"],
|
|
||||||
street_number: address["streetNumber"],
|
|
||||||
street_name: address["streetName"],
|
|
||||||
postal_code: address["postalCode"],
|
|
||||||
city_name: address["cityName"],
|
|
||||||
city_code: address["cityCode"],
|
|
||||||
department_name: address["departmentName"],
|
|
||||||
department_code: address["departmentCode"],
|
|
||||||
region_name: address["regionName"],
|
|
||||||
region_code: address["regionCode"]
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
field :rnf, RNFType, null: true
|
field :rnf, RNFType, null: true
|
||||||
|
field :commune, Types::Champs::CommuneChampType::CommuneType, null: true
|
||||||
|
field :departement, Types::Champs::DepartementChampType::DepartementType, null: true
|
||||||
|
|
||||||
def rnf
|
def rnf
|
||||||
object if object.external_id.present?
|
object if object.external_id.present?
|
||||||
|
|
|
@ -48,8 +48,10 @@ class Champs::AddressChamp < Champs::TextChamp
|
||||||
end
|
end
|
||||||
|
|
||||||
def departement_code_and_name
|
def departement_code_and_name
|
||||||
|
if full_address?
|
||||||
"#{address.fetch('department_code')} – #{departement_name}"
|
"#{address.fetch('department_code')} – #{departement_name}"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def departement
|
def departement
|
||||||
if full_address?
|
if full_address?
|
||||||
|
@ -57,6 +59,12 @@ class Champs::AddressChamp < Champs::TextChamp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def commune_name
|
||||||
|
if full_address?
|
||||||
|
"#{APIGeoService.commune_name(department_code, address['city_code'])} (#{address['postal_code']})"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def commune
|
def commune
|
||||||
if full_address?
|
if full_address?
|
||||||
department_code = address.fetch('department_code')
|
department_code = address.fetch('department_code')
|
||||||
|
|
|
@ -11,8 +11,10 @@ class Champs::CommuneChamp < Champs::TextChamp
|
||||||
end
|
end
|
||||||
|
|
||||||
def departement_code_and_name
|
def departement_code_and_name
|
||||||
|
if departement?
|
||||||
"#{code_departement} – #{departement_name}"
|
"#{code_departement} – #{departement_name}"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def departement
|
def departement
|
||||||
{ code: code_departement, name: departement_name }
|
{ code: code_departement, name: departement_name }
|
||||||
|
|
|
@ -26,10 +26,87 @@ class Champs::RNFChamp < Champ
|
||||||
end
|
end
|
||||||
|
|
||||||
def for_export
|
def for_export
|
||||||
if data
|
if address.present?
|
||||||
[rnf_id, data['title'], data.dig('address', 'label'), data.dig('address', 'cityCode'), "#{data['department']} - #{APIGeoService.departement_name(data['department'])}"]
|
[rnf_id, title, address['label'], address['cityCode'], departement_code_and_name]
|
||||||
else
|
else
|
||||||
[rnf_id, nil, nil, nil, nil]
|
[rnf_id, nil, nil, nil, nil]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def code_departement
|
||||||
|
address.present? && address['departmentCode']
|
||||||
|
end
|
||||||
|
|
||||||
|
def departement?
|
||||||
|
code_departement.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def departement
|
||||||
|
if departement?
|
||||||
|
{ code: code_departement, name: departement_name }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def departement_name
|
||||||
|
APIGeoService.departement_name(code_departement)
|
||||||
|
end
|
||||||
|
|
||||||
|
def departement_code_and_name
|
||||||
|
if departement?
|
||||||
|
"#{code_departement} – #{departement_name}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def commune_name
|
||||||
|
if departement?
|
||||||
|
"#{APIGeoService.commune_name(department_code, address['cityCode'])} (#{address['postalCode']})"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def commune
|
||||||
|
if departement?
|
||||||
|
city_code = address['cityCode']
|
||||||
|
city_name = address['cityName']
|
||||||
|
postal_code = address['postalCode']
|
||||||
|
|
||||||
|
commune_name = APIGeoService.commune_name(department_code, city_code)
|
||||||
|
commune_code = APIGeoService.commune_code(department_code, city_name)
|
||||||
|
|
||||||
|
if commune_name.present?
|
||||||
|
{
|
||||||
|
code: city_code,
|
||||||
|
name: commune_name
|
||||||
|
}
|
||||||
|
elsif commune_code.present?
|
||||||
|
{
|
||||||
|
code: commune_code,
|
||||||
|
name: city_name
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
code: city_code,
|
||||||
|
name: city_name
|
||||||
|
}
|
||||||
|
end.merge(postal_code:)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def rnf_address
|
||||||
|
if departement?
|
||||||
|
{
|
||||||
|
label: address["label"],
|
||||||
|
type: address["type"],
|
||||||
|
street_address: address["streetAddress"],
|
||||||
|
street_number: address["streetNumber"],
|
||||||
|
street_name: address["streetName"],
|
||||||
|
postal_code: address["postalCode"],
|
||||||
|
city_name: address["cityName"],
|
||||||
|
city_code: address["cityCode"],
|
||||||
|
department_name: address["departmentName"],
|
||||||
|
department_code: address["departmentCode"],
|
||||||
|
region_name: address["regionName"],
|
||||||
|
region_code: address["regionCode"]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,2 +1,21 @@
|
||||||
class TypesDeChamp::AddressTypeDeChamp < TypesDeChamp::TextTypeDeChamp
|
class TypesDeChamp::AddressTypeDeChamp < TypesDeChamp::TextTypeDeChamp
|
||||||
|
def tags_for_template
|
||||||
|
tags = super
|
||||||
|
stable_id = @type_de_champ.stable_id
|
||||||
|
tags.push(
|
||||||
|
{
|
||||||
|
libelle: "#{TagsSubstitutionConcern::TagsParser.normalize(libelle)} (Département)",
|
||||||
|
id: "tdc#{stable_id}/departement",
|
||||||
|
description: "#{description} (Département)",
|
||||||
|
lambda: -> (champs) { champs.find { _1.stable_id == stable_id }&.departement_code_and_name }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
libelle: "#{TagsSubstitutionConcern::TagsParser.normalize(libelle)} (Commune)",
|
||||||
|
id: "tdc#{stable_id}/commune",
|
||||||
|
description: "#{description} (Commune)",
|
||||||
|
lambda: -> (champs) { champs.find { _1.stable_id == stable_id }&.commune_name }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
tags
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,4 +2,18 @@ class TypesDeChamp::CommuneTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
||||||
def libelle_for_export(index)
|
def libelle_for_export(index)
|
||||||
[libelle, "#{libelle} (Code insee)", "#{libelle} (Département)"][index]
|
[libelle, "#{libelle} (Code insee)", "#{libelle} (Département)"][index]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tags_for_template
|
||||||
|
tags = super
|
||||||
|
stable_id = @type_de_champ.stable_id
|
||||||
|
tags.push(
|
||||||
|
{
|
||||||
|
libelle: "#{TagsSubstitutionConcern::TagsParser.normalize(libelle)} (Département)",
|
||||||
|
id: "tdc#{stable_id}/departement",
|
||||||
|
description: "#{description} (Département)",
|
||||||
|
lambda: -> (champs) { champs.find { _1.stable_id == stable_id }&.departement_code_and_name }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
tags
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,4 +2,24 @@ class TypesDeChamp::RNFTypeDeChamp < TypesDeChamp::TextTypeDeChamp
|
||||||
def libelle_for_export(index)
|
def libelle_for_export(index)
|
||||||
[libelle, "#{libelle} (Nom)", "#{libelle} (Adresse)", "#{libelle} (Code insee Ville)", "#{libelle} (Département)"][index]
|
[libelle, "#{libelle} (Nom)", "#{libelle} (Adresse)", "#{libelle} (Code insee Ville)", "#{libelle} (Département)"][index]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tags_for_template
|
||||||
|
tags = super
|
||||||
|
stable_id = @type_de_champ.stable_id
|
||||||
|
tags.push(
|
||||||
|
{
|
||||||
|
libelle: "#{TagsSubstitutionConcern::TagsParser.normalize(libelle)} (Département)",
|
||||||
|
id: "tdc#{stable_id}/departement",
|
||||||
|
description: "#{description} (Département)",
|
||||||
|
lambda: -> (champs) { champs.find { _1.stable_id == stable_id }&.departement_code_and_name }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
libelle: "#{TagsSubstitutionConcern::TagsParser.normalize(libelle)} (Commune)",
|
||||||
|
id: "tdc#{stable_id}/commune",
|
||||||
|
description: "#{description} (Commune)",
|
||||||
|
lambda: -> (champs) { champs.find { _1.stable_id == stable_id }&.commune_name }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
tags
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -77,7 +77,7 @@ describe Champs::RNFChamp, type: :model do
|
||||||
describe 'for_export' do
|
describe 'for_export' do
|
||||||
let(:champ) { build(:champ_rnf, external_id:, data: JSON.parse(body)) }
|
let(:champ) { build(:champ_rnf, external_id:, data: JSON.parse(body)) }
|
||||||
it do
|
it do
|
||||||
expect(champ.for_export).to eq(['075-FDD-00003-01', 'Fondation SFR', '16 Rue du Général de Boissieu 75015 Paris', '75115', '75 - Paris'])
|
expect(champ.for_export).to eq(['075-FDD-00003-01', 'Fondation SFR', '16 Rue du Général de Boissieu 75015 Paris', '75115', '75 – Paris'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue