Expose revisions on GraphQL API

This commit is contained in:
Paul Chavard 2020-07-16 12:48:35 +02:00
parent 3b89d04098
commit 91bc2db594
6 changed files with 99 additions and 19 deletions

View file

@ -304,6 +304,7 @@ type Demarche {
"""
updatedSince: ISO8601DateTime
): DossierConnection!
draftRevision: Revision!
groupeInstructeurs: [GroupeInstructeur!]!
id: ID!
@ -311,6 +312,8 @@ type Demarche {
Le numero de la démarche.
"""
number: Int!
publishedRevision: Revision
revisions: [Revision!]!
service: Service!
"""
@ -411,6 +414,7 @@ type Dossier {
Le numero du dossier.
"""
number: Int!
revision: Revision!
"""
L'état du dossier.
@ -1097,6 +1101,17 @@ type RepetitionChamp implements Champ {
stringValue: String
}
type Revision {
annotationDescriptors: [ChampDescriptor!]!
champDescriptors: [ChampDescriptor!]!
"""
Date de la création.
"""
dateCreation: ISO8601DateTime!
id: ID!
}
type SelectionUtilisateur implements GeoArea {
geometry: GeoJSON!
id: ID!

View file

@ -43,6 +43,10 @@ module Types
field :champ_descriptors, [Types::ChampDescriptorType], null: false, method: :types_de_champ
field :annotation_descriptors, [Types::ChampDescriptorType], null: false, method: :types_de_champ_private
field :draft_revision, Types::RevisionType, null: false
field :published_revision, Types::RevisionType, null: true
field :revisions, [Types::RevisionType], null: false
def state
object.aasm.current_state
end
@ -55,6 +59,10 @@ module Types
Loaders::Record.for(Service).load(object.service_id)
end
def revisions
Loaders::Association.for(object.class, :revisions).load(object)
end
def dossiers(updated_since: nil, created_since: nil, state: nil, archived: nil, order:)
dossiers = object.dossiers.state_not_brouillon.for_api_v2

View file

@ -24,18 +24,18 @@ module Types
{ Extensions::Attachment => { attachment: :justificatif_motivation } }
]
field :usager, Types::ProfileType, null: false
field :groupe_instructeur, Types::GroupeInstructeurType, null: false
field :revision, Types::RevisionType, null: false
field :demandeur, Types::DemandeurType, null: false
field :usager, Types::ProfileType, null: false
field :instructeurs, [Types::ProfileType], null: false
field :champs, [Types::ChampType], null: false
field :annotations, [Types::ChampType], null: false
field :messages, [Types::MessageType], null: false
field :avis, [Types::AvisType], null: false
field :groupe_instructeur, Types::GroupeInstructeurType, null: false
field :champs, [Types::ChampType], null: false
field :annotations, [Types::ChampType], null: false
def state
object.state
@ -45,14 +45,26 @@ module Types
Loaders::Record.for(User).load(object.user_id)
end
def instructeurs
Loaders::Association.for(object.class, :followers_instructeurs).load(object)
end
def groupe_instructeur
Loaders::Record.for(GroupeInstructeur).load(object.groupe_instructeur_id)
end
def revision
Loaders::Record.for(ProcedureRevision).load(object.revision_id)
end
def demandeur
if object.procedure.for_individual
Loaders::Association.for(object.class, :individual).load(object)
else
Loaders::Association.for(object.class, :etablissement).load(object)
end
end
def instructeurs
Loaders::Association.for(object.class, :followers_instructeurs).load(object)
end
def messages
Loaders::Association.for(object.class, commentaires: [:instructeur, :user]).load(object)
end
@ -69,14 +81,6 @@ module Types
Loaders::Association.for(object.class, :champs_private).load(object)
end
def demandeur
if object.procedure.for_individual
Loaders::Association.for(object.class, :individual).load(object)
else
Loaders::Association.for(object.class, :etablissement).load(object)
end
end
def self.authorized?(object, context)
authorized_demarche?(object.procedure, context)
end

View file

@ -0,0 +1,17 @@
module Types
class RevisionType < Types::BaseObject
global_id_field :id
field :date_creation, GraphQL::Types::ISO8601DateTime, "Date de la création.", null: false, method: :created_at
field :champ_descriptors, [Types::ChampDescriptorType], null: false
field :annotation_descriptors, [Types::ChampDescriptorType], null: false
def champ_descriptors
Loaders::Association.for(object.class, :types_de_champ).load(object)
end
def annotation_descriptors
Loaders::Association.for(object.class, :types_de_champ_private).load(object)
end
end
end

View file

@ -140,7 +140,7 @@ class Procedure < ApplicationRecord
}
scope :for_api_v2, -> {
includes(administrateurs: :user)
includes(:draft_revision, :published_revision, administrateurs: :user)
}
validates :libelle, presence: true, allow_blank: false, allow_nil: false

View file

@ -63,6 +63,18 @@ describe API::V2::GraphqlController do
email
}
}
revisions {
id
}
draftRevision {
id
}
publishedRevision {
id
champDescriptors {
type
}
}
service {
nom
typeOrganisme
@ -123,6 +135,16 @@ describe API::V2::GraphqlController do
label: "défaut"
}
],
revisions: procedure.revisions.map { |revision| { id: revision.to_typed_id } },
draftRevision: { id: procedure.draft_revision.to_typed_id },
publishedRevision: {
id: procedure.published_revision.to_typed_id,
champDescriptors: procedure.published_types_de_champ.map do |tdc|
{
type: tdc.type_champ
}
end
},
service: {
nom: procedure.service.nom,
typeOrganisme: procedure.service.type_organisme,
@ -255,6 +277,12 @@ describe API::V2::GraphqlController do
number
label
}
revision {
id
champDescriptors {
type
}
}
messages {
email
body
@ -314,6 +342,14 @@ describe API::V2::GraphqlController do
number: dossier.groupe_instructeur.id,
label: dossier.groupe_instructeur.label
},
revision: {
id: dossier.revision.to_typed_id,
champDescriptors: dossier.types_de_champ.map do |tdc|
{
type: tdc.type_champ
}
end
},
demandeur: {
id: dossier.individual.to_typed_id,
nom: dossier.individual.nom,