diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 4d70660eb..4a719effe 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -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! diff --git a/app/graphql/types/demarche_type.rb b/app/graphql/types/demarche_type.rb index ddfad6eb2..79dc5f9c9 100644 --- a/app/graphql/types/demarche_type.rb +++ b/app/graphql/types/demarche_type.rb @@ -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 diff --git a/app/graphql/types/dossier_type.rb b/app/graphql/types/dossier_type.rb index 77026ef92..43bb2106c 100644 --- a/app/graphql/types/dossier_type.rb +++ b/app/graphql/types/dossier_type.rb @@ -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 diff --git a/app/graphql/types/revision_type.rb b/app/graphql/types/revision_type.rb new file mode 100644 index 000000000..3f1ef0847 --- /dev/null +++ b/app/graphql/types/revision_type.rb @@ -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 diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 83a3d54e1..9f31c345b 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -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 diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index 62000633a..10d0c1957 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -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,