demarches-normaliennes/app/graphql/mutations/dossier_passer_en_instruction.rb

27 lines
1.1 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module Mutations
class DossierPasserEnInstruction < Mutations::BaseMutation
include DossierHelper
description "Passer le dossier en instruction."
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
argument :disable_notification, Boolean, "Désactiver lenvoi de lemail de notification après lopération", required: false, default_value: false
field :dossier, Types::DossierType, null: true
field :errors, [Types::ValidationErrorType], null: true
def resolve(dossier:, instructeur:, disable_notification:)
dossier.passer_en_instruction!(instructeur:, disable_notification:)
{ dossier: }
end
def authorized?(dossier:, instructeur:, **args)
if !dossier.en_construction?
return false, { errors: ["Le dossier est déjà #{dossier_display_state(dossier, lower: true)}"] }
end
dossier_authorized_for?(dossier, instructeur)
end
end
end