[GraphQL] Add dossierEnvoyerMessage mutation
This commit is contained in:
parent
f0ac01bf19
commit
ba03dbf8dd
6 changed files with 149 additions and 2 deletions
27
app/graphql/mutations/dossier_envoyer_message.rb
Normal file
27
app/graphql/mutations/dossier_envoyer_message.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
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)
|
||||
message = CommentaireService.build(instructeur, dossier, body: body, piece_jointe: attachment)
|
||||
|
||||
if message.save
|
||||
{ message: message }
|
||||
else
|
||||
{ errors: message.errors.full_messages }
|
||||
end
|
||||
end
|
||||
|
||||
def authorized?(dossier:, instructeur:, body:)
|
||||
instructeur.is_a?(Instructeur) && instructeur.dossiers.exists?(id: dossier.id)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -352,6 +352,33 @@ type DossierEdge {
|
|||
node: Dossier
|
||||
}
|
||||
|
||||
"""
|
||||
Autogenerated input type of DossierEnvoyerMessage
|
||||
"""
|
||||
input DossierEnvoyerMessageInput {
|
||||
attachment: ID
|
||||
body: String!
|
||||
|
||||
"""
|
||||
A unique identifier for the client performing the mutation.
|
||||
"""
|
||||
clientMutationId: String
|
||||
dossierId: ID!
|
||||
instructeurId: ID!
|
||||
}
|
||||
|
||||
"""
|
||||
Autogenerated return type of DossierEnvoyerMessage
|
||||
"""
|
||||
type DossierEnvoyerMessagePayload {
|
||||
"""
|
||||
A unique identifier for the client performing the mutation.
|
||||
"""
|
||||
clientMutationId: String
|
||||
errors: [ValidationError!]
|
||||
message: Message
|
||||
}
|
||||
|
||||
type DossierLinkChamp implements Champ {
|
||||
dossier: Dossier
|
||||
id: ID!
|
||||
|
@ -495,6 +522,11 @@ type Mutation {
|
|||
File information required to prepare a direct upload
|
||||
"""
|
||||
createDirectUpload(input: CreateDirectUploadInput!): CreateDirectUploadPayload
|
||||
|
||||
"""
|
||||
Envoyer un message à l'usager du dossier.
|
||||
"""
|
||||
dossierEnvoyerMessage(input: DossierEnvoyerMessageInput!): DossierEnvoyerMessagePayload
|
||||
}
|
||||
|
||||
enum Order {
|
||||
|
@ -806,4 +838,14 @@ enum TypeDeChamp {
|
|||
"""
|
||||
A valid URL, transported as a string
|
||||
"""
|
||||
scalar URL
|
||||
scalar URL
|
||||
|
||||
"""
|
||||
Éreur de validation
|
||||
"""
|
||||
type ValidationError {
|
||||
"""
|
||||
A description of the error
|
||||
"""
|
||||
message: String!
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
module Types
|
||||
class MutationType < Types::BaseObject
|
||||
field :create_direct_upload, mutation: Mutations::CreateDirectUpload
|
||||
|
||||
field :dossier_envoyer_message, mutation: Mutations::DossierEnvoyerMessage
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue