Add messages and avis types

This commit is contained in:
Paul Chavard 2018-11-23 18:54:51 +01:00
parent 8928eaba11
commit 1c10718c11
5 changed files with 57 additions and 0 deletions

View file

@ -22,6 +22,8 @@ class Api::V2::Schema < GraphQL::Schema
Types::DemarcheType
when Dossier
Types::DossierType
when Commentaire
Types::MessageType
when Instructeur, User
Types::ProfileType
else

View file

@ -1,3 +1,11 @@
type Avis {
answer: String
createdAt: ISO8601DateTime!
email: String!
question: String!
updatedAt: ISO8601DateTime!
}
type ChampInfo {
description: String
id: ID!
@ -111,6 +119,7 @@ enum DemarcheState {
Un dossier
"""
type Dossier {
avis: [Avis!]!
createdAt: ISO8601DateTime!
"""
@ -118,6 +127,7 @@ type Dossier {
"""
id: ID!
instructeurs: [Profile!]!
messages: [Message!]!
motivation: String
"""
@ -200,6 +210,13 @@ An ISO 8601-encoded datetime
"""
scalar ISO8601DateTime
type Message {
attachment: URL
body: String!
createdAt: ISO8601DateTime!
email: String!
}
type Mutation {
}

View file

@ -0,0 +1,12 @@
module Types
class AvisType < Types::BaseObject
global_id_field :id
field :email, String, null: false
field :question, String, null: false, method: :introduction
field :answer, String, null: true
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :attachment_url, Types::URL, null: true, extensions: [
{ Extensions::Attachment => { attachment: :piece_justificative_file } }
]
end
end

View file

@ -27,6 +27,9 @@ module Types
field :usager, Types::ProfileType, null: false
field :instructeurs, [Types::ProfileType], null: false
field :messages, [Types::MessageType], null: false
field :avis, [Types::AvisType], null: false
def state
object.state
end
@ -39,6 +42,14 @@ module Types
Loaders::Association.for(object.class, :followers_instructeurs).load(object)
end
def messages
Loaders::Association.for(object.class, commentaires: [:instructeur, :user]).load(object)
end
def avis
Loaders::Association.for(object.class, avis: [:instructeur, :claimant]).load(object)
end
def self.authorized?(object, context)
authorized_demarche?(object.procedure, context)
end

View file

@ -0,0 +1,15 @@
module Types
class MessageType < Types::BaseObject
global_id_field :id
field :email, String, null: false
field :body, String, null: false
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :attachment_url, Types::URL, null: true, extensions: [
{ Extensions::Attachment => { attachment: :piece_jointe } }
]
def body
object.body.nil? ? "" : object.body
end
end
end