2019-11-13 20:01:58 +01:00
|
|
|
|
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
|
2021-09-01 15:11:11 +02:00
|
|
|
|
argument :disable_notification, Boolean, "Désactiver l’envoi de l’email de notification après l’opération", required: false, default_value: false
|
2019-11-13 20:01:58 +01:00
|
|
|
|
|
|
|
|
|
field :dossier, Types::DossierType, null: true
|
|
|
|
|
field :errors, [Types::ValidationErrorType], null: true
|
|
|
|
|
|
2021-09-01 15:11:11 +02:00
|
|
|
|
def resolve(dossier:, instructeur:, disable_notification:)
|
|
|
|
|
dossier.passer_en_instruction!(instructeur, disable_notification: disable_notification)
|
2019-11-13 20:01:58 +01:00
|
|
|
|
|
2020-12-10 16:23:24 +01:00
|
|
|
|
{ dossier: dossier }
|
2019-11-13 20:01:58 +01:00
|
|
|
|
end
|
|
|
|
|
|
2021-09-01 15:11:11 +02:00
|
|
|
|
def authorized?(dossier:, instructeur:, **args)
|
2020-12-10 16:23:24 +01:00
|
|
|
|
if !dossier.en_construction?
|
|
|
|
|
return false, { errors: ["Le dossier est déjà #{dossier_display_state(dossier, lower: true)}"] }
|
|
|
|
|
end
|
|
|
|
|
dossier_authorized_for?(dossier, instructeur)
|
2019-11-13 20:01:58 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|