2019-11-12 15:51:51 +01:00
|
|
|
module Mutations
|
|
|
|
class DossierEnvoyerMessage < Mutations::BaseMutation
|
|
|
|
description "Envoyer un message à l'usager du dossier."
|
|
|
|
|
|
|
|
argument :dossier_id, ID, required: true, loads: Types::DossierType
|
|
|
|
argument :instructeur_id, ID, required: true, loads: Types::ProfileType
|
|
|
|
argument :body, String, required: true
|
|
|
|
argument :attachment, ID, required: false
|
|
|
|
|
|
|
|
field :message, Types::MessageType, null: true
|
|
|
|
field :errors, [Types::ValidationErrorType], null: true
|
|
|
|
|
|
|
|
def resolve(dossier:, instructeur:, body:, attachment: nil)
|
2021-11-30 18:56:12 +01:00
|
|
|
message = CommentaireService.create(instructeur, dossier, body: body, piece_jointe: attachment)
|
2019-11-12 15:51:51 +01:00
|
|
|
|
2021-11-30 18:56:12 +01:00
|
|
|
if message.errors.empty?
|
2022-12-07 13:21:55 +01:00
|
|
|
{ message: }
|
2019-11-12 15:51:51 +01:00
|
|
|
else
|
|
|
|
{ errors: message.errors.full_messages }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-10 16:23:24 +01:00
|
|
|
def ready?(attachment: nil, **args)
|
|
|
|
if attachment.present?
|
|
|
|
validate_blob(attachment)
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorized?(dossier:, instructeur:, **args)
|
|
|
|
dossier_authorized_for?(dossier, instructeur)
|
2019-11-12 15:51:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|