[GraphQL] Add archiver mutation
This commit is contained in:
parent
a911a71db9
commit
061a743759
4 changed files with 105 additions and 0 deletions
25
app/graphql/mutations/dossier_archiver.rb
Normal file
25
app/graphql/mutations/dossier_archiver.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Mutations
|
||||
class DossierArchiver < Mutations::BaseMutation
|
||||
description "Archiver le dossier."
|
||||
|
||||
argument :dossier_id, ID, "Dossier ID", required: true, loads: Types::DossierType
|
||||
argument :instructeur_id, ID, "Instructeur qui prend la décision sur le dossier.", required: true, loads: Types::ProfileType
|
||||
|
||||
field :dossier, Types::DossierType, null: true
|
||||
field :errors, [Types::ValidationErrorType], null: true
|
||||
|
||||
def resolve(dossier:, instructeur:)
|
||||
if dossier.termine?
|
||||
dossier.archiver!(instructeur)
|
||||
|
||||
{ dossier: dossier }
|
||||
else
|
||||
{ errors: ["Un dossier ne peut être archivé qu’une fois le traitement terminé"] }
|
||||
end
|
||||
end
|
||||
|
||||
def authorized?(dossier:, instructeur:)
|
||||
instructeur.is_a?(Instructeur) && instructeur.dossiers.exists?(id: dossier.id)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue