2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2022-05-20 19:01:54 +02:00
|
|
|
|
module Mutations
|
|
|
|
|
class DossierRepasserEnInstruction < Mutations::BaseMutation
|
|
|
|
|
include DossierHelper
|
|
|
|
|
|
|
|
|
|
description "Re-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 l’envoi de l’email de notification après l’opération", required: false, default_value: false
|
|
|
|
|
|
|
|
|
|
field :dossier, Types::DossierType, null: true
|
|
|
|
|
field :errors, [Types::ValidationErrorType], null: true
|
|
|
|
|
|
|
|
|
|
def resolve(dossier:, instructeur:, disable_notification:)
|
2022-12-07 13:21:55 +01:00
|
|
|
|
dossier.repasser_en_instruction!(instructeur:, disable_notification:)
|
2022-05-20 19:01:54 +02:00
|
|
|
|
|
2022-12-07 13:21:55 +01:00
|
|
|
|
{ dossier: }
|
2022-05-20 19:01:54 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def authorized?(dossier:, instructeur:, **args)
|
2023-04-03 19:01:01 +02:00
|
|
|
|
if !dossier.can_repasser_en_instruction?
|
2022-05-20 19:01:54 +02:00
|
|
|
|
return false, { errors: ["Le dossier est déjà #{dossier_display_state(dossier, lower: true)}"] }
|
|
|
|
|
end
|
|
|
|
|
dossier_authorized_for?(dossier, instructeur)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|