demarches-normaliennes/app/graphql/mutations/dossier_passer_en_instruction.rb
2024-08-22 09:26:48 +02:00

32 lines
1.2 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.

# frozen_string_literal: true
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
if dossier.blocked_with_pending_correction?
return false, { errors: ["Le dossier est en attente de correction"] }
end
dossier_authorized_for?(dossier, instructeur)
end
end
end