2019-11-13 20:01:58 +01:00
|
|
|
|
module Mutations
|
|
|
|
|
class DossierAccepter < Mutations::BaseMutation
|
|
|
|
|
include DossierHelper
|
|
|
|
|
|
|
|
|
|
description "Accepter 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
|
|
|
|
|
argument :motivation, String, required: false
|
|
|
|
|
argument :justificatif, ID, required: false
|
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:, motivation: nil, justificatif: nil, disable_notification:)
|
|
|
|
|
dossier.accepter!(instructeur, motivation, justificatif: justificatif, disable_notification: disable_notification)
|
2020-12-10 16:23:24 +01:00
|
|
|
|
|
|
|
|
|
{ dossier: dossier }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def ready?(justificatif: nil, **args)
|
|
|
|
|
if justificatif.present?
|
|
|
|
|
validate_blob(justificatif)
|
2019-11-13 20:01:58 +01:00
|
|
|
|
else
|
2020-12-10 16:23:24 +01:00
|
|
|
|
true
|
2019-11-13 20:01:58 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-12-10 16:23:24 +01:00
|
|
|
|
def authorized?(dossier:, instructeur:, **args)
|
|
|
|
|
if !dossier.en_instruction?
|
|
|
|
|
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
|