2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2019-11-13 20:01:58 +01:00
|
|
|
|
module Mutations
|
|
|
|
|
class DossierRefuser < Mutations::BaseMutation
|
|
|
|
|
include DossierHelper
|
|
|
|
|
|
|
|
|
|
description "Refuser 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: true
|
|
|
|
|
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:, justificatif: nil, disable_notification:)
|
2022-12-07 13:21:55 +01:00
|
|
|
|
dossier.refuser!(instructeur:, motivation:, justificatif:, disable_notification:)
|
2019-11-13 20:01:58 +01:00
|
|
|
|
|
2022-12-07 13:21:55 +01:00
|
|
|
|
{ dossier: }
|
2020-12-10 16:23:24 +01:00
|
|
|
|
end
|
|
|
|
|
|
2023-02-13 14:25:17 +01:00
|
|
|
|
def authorized_before_load?(justificatif: nil, **args)
|
2020-12-10 16:23:24 +01:00
|
|
|
|
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)
|
2023-05-24 12:03:52 +02:00
|
|
|
|
if dossier.en_instruction? && dossier.any_etablissement_as_degraded_mode?
|
|
|
|
|
return false, { errors: ["Les informations du SIRET du dossier ne sont pas complètes. Veuillez réessayer plus tard."] }
|
|
|
|
|
elsif !dossier.en_instruction? || !dossier.can_terminer?
|
2020-12-10 16:23:24 +01:00
|
|
|
|
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
|