From ee50b8ad2533e88ae99f1e786d94690c5b9f95d4 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 20 May 2022 13:20:17 +0200 Subject: [PATCH] refactor(graphql): fix types_de_champ usage --- app/graphql/types/champ_descriptor_type.rb | 8 ++++---- app/graphql/types/demarche_type.rb | 12 ++++++++++-- app/graphql/types/revision_type.rb | 4 ++-- app/models/procedure_revision_type_de_champ.rb | 4 +--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/graphql/types/champ_descriptor_type.rb b/app/graphql/types/champ_descriptor_type.rb index 1c14c3806..fcefc8010 100644 --- a/app/graphql/types/champ_descriptor_type.rb +++ b/app/graphql/types/champ_descriptor_type.rb @@ -18,14 +18,14 @@ module Types field :options, [String], "List des options d’un champ avec selection.", null: true def champ_descriptors - if object.repetition? - Loaders::Association.for(object.class, :types_de_champ).load(object) + if object.type_de_champ.repetition? + Loaders::Association.for(object.class, :revision_types_de_champ).load(object) end end def options - if object.drop_down_list? - object.drop_down_list_options.reject(&:empty?) + if object.type_de_champ.drop_down_list? + object.type_de_champ.drop_down_list_options.reject(&:empty?) end end end diff --git a/app/graphql/types/demarche_type.rb b/app/graphql/types/demarche_type.rb index adb9eaf84..20512ea03 100644 --- a/app/graphql/types/demarche_type.rb +++ b/app/graphql/types/demarche_type.rb @@ -48,8 +48,8 @@ module Types argument :deleted_since, GraphQL::Types::ISO8601DateTime, required: false, description: "Dossiers supprimés depuis la date." end - field :champ_descriptors, [Types::ChampDescriptorType], null: false, method: :types_de_champ - field :annotation_descriptors, [Types::ChampDescriptorType], null: false, method: :types_de_champ_private + field :champ_descriptors, [Types::ChampDescriptorType], null: false + field :annotation_descriptors, [Types::ChampDescriptorType], null: false field :draft_revision, Types::RevisionType, null: false field :published_revision, Types::RevisionType, null: true @@ -120,6 +120,14 @@ module Types dossiers.order(deleted_at: order) end + def champ_descriptors + object.active_revision.revision_types_de_champ_public + end + + def annotation_descriptors + object.active_revision.revision_types_de_champ_private + end + def self.authorized?(object, context) context.authorized_demarche?(object) end diff --git a/app/graphql/types/revision_type.rb b/app/graphql/types/revision_type.rb index eb8a09b5c..01189351c 100644 --- a/app/graphql/types/revision_type.rb +++ b/app/graphql/types/revision_type.rb @@ -8,11 +8,11 @@ module Types field :annotation_descriptors, [Types::ChampDescriptorType], null: false def champ_descriptors - Loaders::Association.for(object.class, :types_de_champ_public).load(object) + Loaders::Association.for(object.class, revision_types_de_champ_public: :type_de_champ).load(object) end def annotation_descriptors - Loaders::Association.for(object.class, :types_de_champ_private).load(object) + Loaders::Association.for(object.class, revision_types_de_champ_private: :type_de_champ).load(object) end end end diff --git a/app/models/procedure_revision_type_de_champ.rb b/app/models/procedure_revision_type_de_champ.rb index 8450f687a..664515005 100644 --- a/app/models/procedure_revision_type_de_champ.rb +++ b/app/models/procedure_revision_type_de_champ.rb @@ -22,9 +22,7 @@ class ProcedureRevisionTypeDeChamp < ApplicationRecord scope :public_only, -> { joins(:type_de_champ).where(types_de_champ: { private: false }) } scope :private_only, -> { joins(:type_de_champ).where(types_de_champ: { private: true }) } - def private? - type_de_champ.private? - end + delegate :stable_id, :libelle, :description, :type_champ, :mandatory?, :private?, :to_typed_id, to: :type_de_champ def child? parent_id.present?