[GraphQL] add better errors when attachments are not properly used
This commit is contained in:
parent
68b849c827
commit
b897e0cc1c
6 changed files with 56 additions and 0 deletions
|
@ -1,4 +1,16 @@
|
|||
module Mutations
|
||||
class BaseMutation < GraphQL::Schema::RelayClassicMutation
|
||||
def validate_blob(blob_id)
|
||||
if blob_id.present?
|
||||
begin
|
||||
blob = ActiveStorage::Blob.find_signed(blob_id)
|
||||
blob.identify
|
||||
rescue ActiveStorage::FileNotFoundError
|
||||
return { errors: ['Le fichier n’a pas été correctement téléversé sur le serveur de stockage'] }
|
||||
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
||||
return { errors: ['L’identifiant du fichier téléversé est invalide'] }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,6 +14,10 @@ module Mutations
|
|||
|
||||
def resolve(dossier:, instructeur:, motivation: nil, justificatif: nil)
|
||||
if dossier.en_instruction?
|
||||
errors = validate_blob(justificatif)
|
||||
if errors
|
||||
return errors
|
||||
end
|
||||
dossier.accepter!(instructeur, motivation, justificatif)
|
||||
|
||||
{ dossier: dossier }
|
||||
|
|
|
@ -14,6 +14,10 @@ module Mutations
|
|||
|
||||
def resolve(dossier:, instructeur:, motivation:, justificatif: nil)
|
||||
if dossier.en_instruction?
|
||||
errors = validate_blob(justificatif)
|
||||
if errors
|
||||
return errors
|
||||
end
|
||||
dossier.classer_sans_suite!(instructeur, motivation, justificatif)
|
||||
|
||||
{ dossier: dossier }
|
||||
|
|
|
@ -11,6 +11,10 @@ module Mutations
|
|||
field :errors, [Types::ValidationErrorType], null: true
|
||||
|
||||
def resolve(dossier:, instructeur:, body:, attachment: nil)
|
||||
errors = validate_blob(attachment)
|
||||
if errors
|
||||
return errors
|
||||
end
|
||||
message = CommentaireService.build(instructeur, dossier, body: body, piece_jointe: attachment)
|
||||
|
||||
if message.save
|
||||
|
|
|
@ -14,6 +14,10 @@ module Mutations
|
|||
|
||||
def resolve(dossier:, instructeur:, motivation:, justificatif: nil)
|
||||
if dossier.en_instruction?
|
||||
errors = validate_blob(justificatif)
|
||||
if errors
|
||||
return errors
|
||||
end
|
||||
dossier.refuser!(instructeur, motivation, justificatif)
|
||||
|
||||
{ dossier: dossier }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue