2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
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:)
|
2022-12-07 13:21:55 +01:00
|
|
|
|
dossier.passer_en_instruction!(instructeur:, disable_notification:)
|
2019-11-13 20:01:58 +01:00
|
|
|
|
|
2022-12-07 13:21:55 +01:00
|
|
|
|
{ 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
|
2024-06-04 17:40:48 +02:00
|
|
|
|
if dossier.blocked_with_pending_correction?
|
|
|
|
|
return false, { errors: ["Le dossier est en attente de correction"] }
|
|
|
|
|
end
|
2020-12-10 16:23:24 +01:00
|
|
|
|
dossier_authorized_for?(dossier, instructeur)
|
2019-11-13 20:01:58 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|