diff --git a/app/graphql/api/v2/schema.rb b/app/graphql/api/v2/schema.rb index bef5be7c3..a32238cfb 100644 --- a/app/graphql/api/v2/schema.rb +++ b/app/graphql/api/v2/schema.rb @@ -63,6 +63,7 @@ class API::V2::Schema < GraphQL::Schema Types::Champs::DepartementChampType, Types::Champs::DossierLinkChampType, Types::Champs::EpciChampType, + Types::Champs::RNFChampType, Types::Champs::IntegerNumberChampType, Types::Champs::LinkedDropDownListChampType, Types::Champs::MultipleDropDownListChampType, diff --git a/app/graphql/api/v2/stored_query.rb b/app/graphql/api/v2/stored_query.rb index 08c93bee9..9860df3d9 100644 --- a/app/graphql/api/v2/stored_query.rb +++ b/app/graphql/api/v2/stored_query.rb @@ -564,6 +564,11 @@ class API::V2::StoredQuery ...PersonneMoraleFragment } } + ... on RNFChamp { + rnf { + ...RNFFragment + } + } } fragment PersonneMoraleFragment on PersonneMorale { @@ -666,6 +671,14 @@ class API::V2::StoredQuery postalCode } + fragment RNFFragment on RNF { + id + title + address { + ...AddressFragment + } + } + fragment PageInfoFragment on PageInfo { hasPreviousPage hasNextPage diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index f0af9351a..2d7d681fa 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -3582,6 +3582,33 @@ type RNAChampDescriptor implements ChampDescriptor { type: TypeDeChamp! @deprecated(reason: "Utilisez le champ `__typename` à la place.") } +type RNF { + address: Address + id: String! + title: String +} + +type RNFChamp implements Champ { + id: ID! + + """ + Libellé du champ. + """ + label: String! + prefilled: Boolean! + rnf: RNF + + """ + La valeur du champ sous forme texte. + """ + stringValue: String + + """ + Date de dernière modification du champ. + """ + updatedAt: ISO8601DateTime! +} + type RNFChampDescriptor 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 0d54ee51e..827cc5e77 100644 --- a/app/graphql/types/champ_type.rb +++ b/app/graphql/types/champ_type.rb @@ -75,6 +75,8 @@ module Types Types::Champs::TitreIdentiteChampType when ::Champs::EpciChamp Types::Champs::EpciChampType + when ::Champs::RNFChamp + Types::Champs::RNFChampType else Types::Champs::TextChampType end diff --git a/app/graphql/types/champs/rnf_champ_type.rb b/app/graphql/types/champs/rnf_champ_type.rb new file mode 100644 index 000000000..13f39fed9 --- /dev/null +++ b/app/graphql/types/champs/rnf_champ_type.rb @@ -0,0 +1,45 @@ +module Types::Champs + class RNFChampType < Types::BaseObject + implements Types::ChampType + + class RNFType < Types::BaseObject + field :id, String, null: false + field :title, String, null: true + field :address, Types::AddressType, null: true + + 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 + + field :rnf, RNFType, null: true + + def rnf + object if object.external_id.present? + end + end +end diff --git a/app/models/champs/rnf_champ.rb b/app/models/champs/rnf_champ.rb index 938729401..13779a225 100644 --- a/app/models/champs/rnf_champ.rb +++ b/app/models/champs/rnf_champ.rb @@ -5,6 +5,10 @@ class Champs::RNFChamp < Champ external_id end + def value + rnf_id + end + def fetch_external_data RNFService.new.(rnf_id:) end