From 13ab3b465e893d5d274493ec7f144023556c5836 Mon Sep 17 00:00:00 2001 From: pedong Date: Fri, 21 Feb 2020 11:29:17 +0100 Subject: [PATCH 1/2] add groupe_instructeur in dossier_type --- app/graphql/schema.graphql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 15cdb6803..6ae3e2e90 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -1190,4 +1190,4 @@ type ValidationError { A description of the error """ message: String! -} \ No newline at end of file +} From 62f82cc83cb6fdb0f7bf7c815038976996885bc6 Mon Sep 17 00:00:00 2001 From: pedong Date: Fri, 21 Feb 2020 11:57:36 +0100 Subject: [PATCH 2/2] add dossierChangerGroupeInstructeur mutation --- app/graphql/api/v2/schema.rb | 2 + .../dossier_changer_groupe_instructeur.rb | 26 ++++++++++ app/graphql/schema.graphql | 39 ++++++++++++++- app/graphql/types/mutation_type.rb | 1 + .../api/v2/graphql_controller_spec.rb | 47 +++++++++++++++++++ 5 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 app/graphql/mutations/dossier_changer_groupe_instructeur.rb diff --git a/app/graphql/api/v2/schema.rb b/app/graphql/api/v2/schema.rb index 10b1bfa13..777f08014 100644 --- a/app/graphql/api/v2/schema.rb +++ b/app/graphql/api/v2/schema.rb @@ -30,6 +30,8 @@ class Api::V2::Schema < GraphQL::Schema Types::PersonnePhysiqueType when Etablissement Types::PersonneMoraleType + when GroupeInstructeur + Types::GroupeInstructeurType else raise GraphQL::ExecutionError.new("Unexpected object: #{obj}") end diff --git a/app/graphql/mutations/dossier_changer_groupe_instructeur.rb b/app/graphql/mutations/dossier_changer_groupe_instructeur.rb new file mode 100644 index 000000000..ccb2ca906 --- /dev/null +++ b/app/graphql/mutations/dossier_changer_groupe_instructeur.rb @@ -0,0 +1,26 @@ +module Mutations + class DossierChangerGroupeInstructeur < Mutations::BaseMutation + include DossierHelper + + description "Changer le grope instructeur du dossier." + + argument :dossier_id, ID, "Dossier ID", required: true, loads: Types::DossierType + argument :groupe_instructeur_id, ID, "Group instructeur a affecter", required: true, loads: Types::GroupeInstructeurType + + field :dossier, Types::DossierType, null: true + field :errors, [Types::ValidationErrorType], null: true + + def resolve(dossier:, groupe_instructeur:) + if dossier.groupe_instructeur == groupe_instructeur + { errors: ["Le dossier est déjà avec le grope instructeur: '#{groupe_instructeur.label}'"] } + else + dossier.update!(groupe_instructeur: groupe_instructeur) + { dossier: dossier } + end + end + + def authorized?(dossier:, groupe_instructeur:) + dossier.groupe_instructeur.procedure == groupe_instructeur.procedure + end + end +end diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 6ae3e2e90..7558a5f8b 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -438,6 +438,38 @@ type DossierAccepterPayload { errors: [ValidationError!] } +""" +Autogenerated input type of DossierChangerGroupeInstructeur +""" +input DossierChangerGroupeInstructeurInput { + """ + A unique identifier for the client performing the mutation. + """ + clientMutationId: String + + """ + Dossier ID + """ + dossierId: ID! + + """ + Group instructeur a affecter + """ + groupeInstructeurId: ID! +} + +""" +Autogenerated return type of DossierChangerGroupeInstructeur +""" +type DossierChangerGroupeInstructeurPayload { + """ + A unique identifier for the client performing the mutation. + """ + clientMutationId: String + dossier: Dossier + errors: [ValidationError!] +} + """ Autogenerated input type of DossierClasserSansSuite """ @@ -790,6 +822,11 @@ type Mutation { """ dossierAccepter(input: DossierAccepterInput!): DossierAccepterPayload + """ + Changer le grope instructeur du dossier. + """ + dossierChangerGroupeInstructeur(input: DossierChangerGroupeInstructeurInput!): DossierChangerGroupeInstructeurPayload + """ Classer le dossier sans suite. """ @@ -1190,4 +1227,4 @@ type ValidationError { A description of the error """ message: String! -} +} \ No newline at end of file diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb index 22ad55981..1a0e8e32f 100644 --- a/app/graphql/types/mutation_type.rb +++ b/app/graphql/types/mutation_type.rb @@ -7,5 +7,6 @@ module Types field :dossier_classer_sans_suite, mutation: Mutations::DossierClasserSansSuite field :dossier_refuser, mutation: Mutations::DossierRefuser field :dossier_accepter, mutation: Mutations::DossierAccepter + field :dossier_changer_groupe_instructeur, mutation: Mutations::DossierChangerGroupeInstructeur end end diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index feab5a789..57e5e4f7f 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -686,6 +686,53 @@ describe API::V2::GraphqlController do expect(data[:signedBlobId]).not_to be_nil end end + + describe 'dossierChangerGroupeInstructeur' do + let(:query) do + "mutation { + dossierChangerGroupeInstructeur(input: { + dossierId: \"#{dossier.to_typed_id}\", + groupeInstructeurId: \"#{dossier.groupe_instructeur.to_typed_id}\" + }) { + errors { + message + } + } + }" + end + + it "validation error" do + expect(gql_errors).to eq(nil) + + expect(gql_data).to eq(dossierChangerGroupeInstructeur: { + errors: [{ message: "Le dossier est déjà avec le grope instructeur: 'défaut'" }] + }) + end + + context "should changer groupe instructeur" do + let!(:new_groupe_instructeur) { procedure.groupe_instructeurs.create(label: 'new groupe instructeur') } + let(:query) do + "mutation { + dossierChangerGroupeInstructeur(input: { + dossierId: \"#{dossier.to_typed_id}\", + groupeInstructeurId: \"#{new_groupe_instructeur.to_typed_id}\" + }) { + errors { + message + } + } + }" + end + + it "change made" do + expect(gql_errors).to eq(nil) + + expect(gql_data).to eq(dossierChangerGroupeInstructeur: { + errors: nil + }) + end + end + end end end