From 072156d38ee2857829e60cc49c15bd822b69cfbb Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 21 Dec 2022 17:35:05 +0100 Subject: [PATCH] feat(graphql): add pays champ to API --- app/graphql/api/v2/schema.rb | 1 + app/graphql/api/v2/stored_query.rb | 6 ++++++ app/graphql/schema.graphql | 20 ++++++++++++++++++++ app/graphql/types/champ_type.rb | 6 ++++++ app/graphql/types/champs/pays_champ_type.rb | 16 ++++++++++++++++ app/models/champs/pays_champ.rb | 10 ++++------ 6 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 app/graphql/types/champs/pays_champ_type.rb diff --git a/app/graphql/api/v2/schema.rb b/app/graphql/api/v2/schema.rb index e42a4af17..9f66b2814 100644 --- a/app/graphql/api/v2/schema.rb +++ b/app/graphql/api/v2/schema.rb @@ -59,6 +59,7 @@ class API::V2::Schema < GraphQL::Schema Types::Champs::IntegerNumberChampType, Types::Champs::LinkedDropDownListChampType, Types::Champs::MultipleDropDownListChampType, + Types::Champs::PaysChampType, Types::Champs::PieceJustificativeChampType, Types::Champs::RegionChampType, Types::Champs::RepetitionChampType, diff --git a/app/graphql/api/v2/stored_query.rb b/app/graphql/api/v2/stored_query.rb index f53e113b2..fcf59f8c8 100644 --- a/app/graphql/api/v2/stored_query.rb +++ b/app/graphql/api/v2/stored_query.rb @@ -454,6 +454,12 @@ class API::V2::StoredQuery code } } + ... on PaysChamp { + pays { + name + code + } + } ... on SiretChamp { etablissement { ...PersonneMoraleFragment diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 4de9bfae4..6c2e4de33 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -2017,6 +2017,26 @@ type ParcelleCadastrale implements GeoArea { surfaceParcelle: Float! @deprecated(reason: "Utilisez le champ `surface` à la place.") } +type Pays { + code: String! + name: String! +} + +type PaysChamp implements Champ { + id: ID! + + """ + Libellé du champ. + """ + label: String! + pays: Pays + + """ + La valeur du champ sous forme texte. + """ + stringValue: String +} + type PersonneMorale implements Demandeur { address: Address! adresse: String! @deprecated(reason: "Utilisez le champ `address.label` à la place.") diff --git a/app/graphql/types/champ_type.rb b/app/graphql/types/champ_type.rb index d1f07b3f7..0d037b0b0 100644 --- a/app/graphql/types/champ_type.rb +++ b/app/graphql/types/champ_type.rb @@ -43,6 +43,12 @@ module Types else Types::Champs::TextChampType end + when ::Champs::PaysChamp + if context.has_fragment?(:PaysChamp) + Types::Champs::PaysChampType + else + Types::Champs::TextChampType + end when ::Champs::DossierLinkChamp Types::Champs::DossierLinkChampType when ::Champs::PieceJustificativeChamp diff --git a/app/graphql/types/champs/pays_champ_type.rb b/app/graphql/types/champs/pays_champ_type.rb new file mode 100644 index 000000000..b1b8e32cd --- /dev/null +++ b/app/graphql/types/champs/pays_champ_type.rb @@ -0,0 +1,16 @@ +module Types::Champs + class PaysChampType < Types::BaseObject + implements Types::ChampType + + class PaysType < Types::BaseObject + field :name, String, null: false + field :code, String, null: false + end + + field :pays, PaysType, null: true + + def pays + object if object.external_id.present? + end + end +end diff --git a/app/models/champs/pays_champ.rb b/app/models/champs/pays_champ.rb index 8246a18ee..170659903 100644 --- a/app/models/champs/pays_champ.rb +++ b/app/models/champs/pays_champ.rb @@ -22,15 +22,15 @@ # class Champs::PaysChamp < Champs::TextChamp def for_export - [formatted_value, code] + [name, code] end def to_s - formatted_value + name end def for_tag - formatted_value + name end def selected @@ -54,9 +54,7 @@ class Champs::PaysChamp < Champs::TextChamp external_id || APIGeoService.country_code(value) end - private - - def formatted_value + def name if external_id APIGeoService.country_name(external_id) else