From 6ff07d04a460d6ab730d0d7eb623264da4eb8d5b Mon Sep 17 00:00:00 2001 From: Lisa Durand Date: Mon, 5 Feb 2024 18:47:40 +0100 Subject: [PATCH] add rna type de champ to harmonize api with rnf --- app/graphql/api/v2/schema.rb | 1 + app/graphql/schema.graphql | 29 +++++++++++++++++++ app/graphql/types/champ_type.rb | 2 ++ app/graphql/types/champs/rna_champ_type.rb | 23 +++++++++++++++ app/lib/api_entreprise/rna_adapter.rb | 2 +- app/models/champs/rna_champ.rb | 26 +++++++++++++---- spec/lib/api_entreprise/rna_adapter_spec.rb | 10 +++++++ ...hamp_association_fetchable_concern_spec.rb | 12 +++++++- 8 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 app/graphql/types/champs/rna_champ_type.rb diff --git a/app/graphql/api/v2/schema.rb b/app/graphql/api/v2/schema.rb index 570ec91f7f9..6ff534a276b 100644 --- a/app/graphql/api/v2/schema.rb +++ b/app/graphql/api/v2/schema.rb @@ -63,6 +63,7 @@ def self.resolve_type(type_definition, object, ctx) Types::Champs::DepartementChampType, Types::Champs::DossierLinkChampType, Types::Champs::EpciChampType, + Types::Champs::RNAChampType, Types::Champs::RNFChampType, Types::Champs::IntegerNumberChampType, Types::Champs::LinkedDropDownListChampType, diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 7c87f2acfcb..cdfb5bd001b 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -3620,6 +3620,35 @@ type Query { ): GroupeInstructeurWithDossiers! } +type RNA { + address: Address + id: String! + title: String +} + +type RNAChamp implements Champ { + commune: Commune + departement: Departement + id: ID! + + """ + Libellé du champ. + """ + label: String! + prefilled: Boolean! + rna: RNA + + """ + La valeur du champ sous forme texte. + """ + stringValue: String + + """ + Date de dernière modification du champ. + """ + updatedAt: ISO8601DateTime! +} + type RNAChampDescriptor implements ChampDescriptor { """ Description des champs d’un bloc répétable. diff --git a/app/graphql/types/champ_type.rb b/app/graphql/types/champ_type.rb index 00e8565fec1..8ad25d3b479 100644 --- a/app/graphql/types/champ_type.rb +++ b/app/graphql/types/champ_type.rb @@ -75,6 +75,8 @@ def resolve_type(object, context) Types::Champs::TitreIdentiteChampType when ::Champs::EpciChamp Types::Champs::EpciChampType + when ::Champs::RNAChamp + Types::Champs::RNAChampType when ::Champs::RNFChamp Types::Champs::RNFChampType when ::Champs::EngagementJuridiqueChamp diff --git a/app/graphql/types/champs/rna_champ_type.rb b/app/graphql/types/champs/rna_champ_type.rb new file mode 100644 index 00000000000..e41cce72fbe --- /dev/null +++ b/app/graphql/types/champs/rna_champ_type.rb @@ -0,0 +1,23 @@ +module Types::Champs + class RNAChampType < Types::BaseObject + implements Types::ChampType + + class RNAType < Types::BaseObject + field :id, String, null: false, method: :value + field :title, String, null: true, method: :title + field :address, Types::AddressType, null: true, method: :rna_address + end + + field :rna, RNAType, null: true + field :commune, Types::Champs::CommuneChampType::CommuneType, null: true + field :departement, Types::Champs::DepartementChampType::DepartementType, null: true + + def rna_id + object.value + end + + def rna + object if object.value.present? + end + end +end diff --git a/app/lib/api_entreprise/rna_adapter.rb b/app/lib/api_entreprise/rna_adapter.rb index a35b24f3fbc..e4b5d061c5e 100644 --- a/app/lib/api_entreprise/rna_adapter.rb +++ b/app/lib/api_entreprise/rna_adapter.rb @@ -24,7 +24,7 @@ def process_params # see: https://mattermost.incubateur.net/betagouv/pl/r6txumw9cpyx58rt7iq5dte9qe "association_date_declaration" => meta[:date_derniere_mise_a_jour_rna], "association_date_publication" => data[:date_publication_journal_officiel], - "address" => data[:adresse_siege] + "adresse" => data[:adresse_siege] } end end diff --git a/app/models/champs/rna_champ.rb b/app/models/champs/rna_champ.rb index 19f9ce9f251..c0008fe8045 100644 --- a/app/models/champs/rna_champ.rb +++ b/app/models/champs/rna_champ.rb @@ -11,11 +11,6 @@ def title data&.dig("association_titre") end - def full_address - address = data&.dig("address") - "#{address["numero_voie"]} #{address["type_voie"]} #{address["libelle_voie"]} #{address["code_postal"]} #{address["commune"]}" - end - def identifier title.present? ? "#{value} (#{title})" : value end @@ -27,4 +22,25 @@ def for_export def search_terms etablissement.present? ? etablissement.search_terms : [value] end + + def full_address + address = data&.dig("adresse") + return if address.blank? + "#{address["numero_voie"]} #{address["type_voie"]} #{address["libelle_voie"]} #{address["code_postal"]} #{address["commune"]}" + end + + def rna_address + address = data&.dig("adresse") + return if address.blank? + { + label: full_address, + type: "housenumber", + street_address: address["libelle_voie"] ? [address["numero_voie"], address["type_voie"], address["libelle_voie"]].compact.join(' ') : nil, + street_number: address["numero_voie"], + street_name: [address["type_voie"], address["libelle_voie"]].compact.join(' '), + postal_code: address["code_postal"], + city_name: address["commune"], + city_code: address["code_insee"] + } + end end diff --git a/spec/lib/api_entreprise/rna_adapter_spec.rb b/spec/lib/api_entreprise/rna_adapter_spec.rb index e199e4c8dae..e5be9dea8fa 100644 --- a/spec/lib/api_entreprise/rna_adapter_spec.rb +++ b/spec/lib/api_entreprise/rna_adapter_spec.rb @@ -31,6 +31,16 @@ expect(subject["association_objet"]).to eq("L'association a pour objet de promouvoir la pratique du sport de haut niveau et de contribuer à la formation des jeunes sportifs.") expect(subject["association_date_declaration"]).to eq("2019-01-01") expect(subject["association_date_publication"]).to eq("2018-01-01") + expect(subject["adresse"]).to eq({ + complement: "", + numero_voie: "33", + type_voie: "rue", + libelle_voie: "de Modagor", + distribution: "dummy", + code_insee: "75108", + code_postal: "75009", + commune: "Paris" + }) end end end diff --git a/spec/models/concern/rna_champ_association_fetchable_concern_spec.rb b/spec/models/concern/rna_champ_association_fetchable_concern_spec.rb index d84f42aa53f..4d8692786e0 100644 --- a/spec/models/concern/rna_champ_association_fetchable_concern_spec.rb +++ b/spec/models/concern/rna_champ_association_fetchable_concern_spec.rb @@ -68,7 +68,17 @@ "association_date_creation" => "2015-01-01", "association_date_declaration" => "2019-01-01", "association_date_publication" => "2018-01-01", - "association_rna" => "W751080001" + "association_rna" => "W751080001", + "adresse" => { + "complement" => "", + "numero_voie" => "33", + "type_voie" => "rue", + "libelle_voie" => "de Modagor", + "distribution" => "dummy", + "code_insee" => "75108", + "code_postal" => "75009", + "commune" => "Paris" + } } end end