From 3f36153807d5a2d07e801478c391d9d0f79a93ad Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 24 Sep 2019 19:41:48 +0200 Subject: [PATCH] [GraphQL] Add groupe_instructeurs to demarche --- app/graphql/schema.graphql | 11 ++++++++++- app/graphql/types/demarche_type.rb | 6 +++--- app/graphql/types/groupe_instructeur_type.rb | 17 +++++++++++++++++ .../api/v2/graphql_controller_spec.rb | 7 +++++++ 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 app/graphql/types/groupe_instructeur_type.rb diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 089f46e77..a9ce16d5a 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -102,8 +102,8 @@ type Demarche { """ since: ISO8601DateTime ): DossierConnection! + groupeInstructeurs: [GroupeInstructeur!]! id: ID! - instructeurs: [Profile!]! """ Le numero de la démarche. @@ -279,6 +279,15 @@ type GeoJSON { type: String! } +""" +Un groupe instructeur +""" +type GroupeInstructeur { + id: ID! + instructeurs: [Profile!]! + label: String! +} + """ An ISO 8601-encoded datetime """ diff --git a/app/graphql/types/demarche_type.rb b/app/graphql/types/demarche_type.rb index 6e5dabcb3..37782aafe 100644 --- a/app/graphql/types/demarche_type.rb +++ b/app/graphql/types/demarche_type.rb @@ -18,7 +18,7 @@ module Types field :updated_at, GraphQL::Types::ISO8601DateTime, null: false field :archived_at, GraphQL::Types::ISO8601DateTime, null: true - field :instructeurs, [Types::ProfileType], null: false + field :groupe_instructeurs, [Types::GroupeInstructeurType], null: false field :dossiers, Types::DossierType.connection_type, "Liste de tous les dossiers d'une démarche.", null: false do argument :ids, [ID], required: false, description: "Filtrer les dossiers par ID." @@ -32,8 +32,8 @@ module Types object.aasm.current_state end - def instructeurs - Loaders::Association.for(Procedure, :instructeurs).load(object) + def groupe_instructeurs + Loaders::Association.for(object.class, groupe_instructeurs: { procedure: [:administrateurs] }).load(object) end def dossiers(ids: nil, since: nil) diff --git a/app/graphql/types/groupe_instructeur_type.rb b/app/graphql/types/groupe_instructeur_type.rb new file mode 100644 index 000000000..94cd19a57 --- /dev/null +++ b/app/graphql/types/groupe_instructeur_type.rb @@ -0,0 +1,17 @@ +module Types + class GroupeInstructeurType < Types::BaseObject + description "Un groupe instructeur" + + global_id_field :id + field :label, String, null: false + field :instructeurs, [Types::ProfileType], null: false + end + + def instructeurs + Loaders::Association.for(object.class, :instructeurs).load(object) + end + + def self.authorized?(object, context) + authorized_demarche?(object.procedure, context) + end +end diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index d7df04f8e..384d85808 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -24,6 +24,12 @@ describe API::V2::GraphqlController do createdAt updatedAt archivedAt + groupeInstructeurs { + label + instructeurs { + email + } + } champDescriptors { id type @@ -67,6 +73,7 @@ describe API::V2::GraphqlController do archivedAt: nil, createdAt: procedure.created_at.iso8601, updatedAt: procedure.updated_at.iso8601, + groupeInstructeurs: [{ instructeurs: [], label: "défaut" }], champDescriptors: procedure.types_de_champ.map do |tdc| { id: tdc.to_typed_id,