feat(graphql): expose deleted dossiers on groupe instructeur

This commit is contained in:
Paul Chavard 2022-11-04 09:07:56 +00:00
parent 3ced06d59b
commit 1e8a440166
5 changed files with 70 additions and 0 deletions

View file

@ -102,7 +102,12 @@ class API::V2::StoredQuery
$revision: ID $revision: ID
$createdSince: ISO8601DateTime $createdSince: ISO8601DateTime
$updatedSince: ISO8601DateTime $updatedSince: ISO8601DateTime
$deletedOrder: Order
$deletedFirst: Int
$deletedAfter: String
$deletedSince: ISO8601DateTime
$includeDossiers: Boolean = false $includeDossiers: Boolean = false
$includeDeletedDossiers: Boolean = false
$includeChamps: Boolean = true $includeChamps: Boolean = true
$includeAnotations: Boolean = true $includeAnotations: Boolean = true
$includeTraitements: Boolean = true $includeTraitements: Boolean = true
@ -136,6 +141,19 @@ class API::V2::StoredQuery
...DossierFragment ...DossierFragment
} }
} }
deletedDossiers(
order: $deletedOrder
first: $deletedFirst
after: $deletedAfter
deletedSince: $deletedSince
) @include(if: $includeDeletedDossiers) {
pageInfo {
...PageInfoFragment
}
nodes {
...DeletedDossierFragment
}
}
} }
} }

View file

@ -1537,6 +1537,41 @@ type GroupeInstructeur {
Un groupe instructeur avec ses dossiers Un groupe instructeur avec ses dossiers
""" """
type GroupeInstructeurWithDossiers { type GroupeInstructeurWithDossiers {
"""
Liste de tous les dossiers supprimés dun groupe instructeur.
"""
deletedDossiers(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
"""
Returns the elements in the list that come before the specified cursor.
"""
before: String
"""
Dossiers supprimés depuis la date.
"""
deletedSince: ISO8601DateTime
"""
Returns the first _n_ elements from the list.
"""
first: Int
"""
Returns the last _n_ elements from the list.
"""
last: Int
"""
Lordre des dossiers supprimés.
"""
order: Order = ASC
): DeletedDossierConnection!
""" """
Liste de tous les dossiers dun groupe instructeur. Liste de tous les dossiers dun groupe instructeur.
""" """

View file

@ -13,6 +13,11 @@ module Types
argument :min_revision, ID, required: false, description: "Seulement les dossiers pour les révisons après la révision donnée." argument :min_revision, ID, required: false, description: "Seulement les dossiers pour les révisons après la révision donnée."
end end
field :deleted_dossiers, Types::DeletedDossierType.connection_type, "Liste de tous les dossiers supprimés dun groupe instructeur.", null: false do
argument :order, Types::Order, default_value: :asc, required: false, description: "Lordre des dossiers supprimés."
argument :deleted_since, GraphQL::Types::ISO8601DateTime, required: false, description: "Dossiers supprimés depuis la date."
end
def dossiers(updated_since: nil, created_since: nil, state: nil, archived: nil, revision: nil, max_revision: nil, min_revision: nil, order:, lookahead:) def dossiers(updated_since: nil, created_since: nil, state: nil, archived: nil, revision: nil, max_revision: nil, min_revision: nil, order:, lookahead:)
dossiers = object dossiers = object
.dossiers .dossiers
@ -55,5 +60,15 @@ module Types
# https://graphql-ruby.org/queries/lookahead.html # https://graphql-ruby.org/queries/lookahead.html
Connections::DossiersConnection.new(dossiers, lookahead: lookahead) Connections::DossiersConnection.new(dossiers, lookahead: lookahead)
end end
def deleted_dossiers(deleted_since: nil, order:)
dossiers = object.deleted_dossiers
if deleted_since.present?
dossiers = dossiers.deleted_since(deleted_since)
end
dossiers.order(deleted_at: order)
end
end end
end end

View file

@ -16,6 +16,7 @@
# #
class DeletedDossier < ApplicationRecord class DeletedDossier < ApplicationRecord
belongs_to :procedure, -> { with_discarded }, inverse_of: :deleted_dossiers, optional: false belongs_to :procedure, -> { with_discarded }, inverse_of: :deleted_dossiers, optional: false
belongs_to :groupe_instructeur, inverse_of: :deleted_dossiers, optional: true
scope :order_by_updated_at, -> (order = :desc) { order(created_at: order) } scope :order_by_updated_at, -> (order = :desc) { order(created_at: order) }
scope :deleted_since, -> (since) { where('deleted_dossiers.deleted_at >= ?', since) } scope :deleted_since, -> (since) { where('deleted_dossiers.deleted_at >= ?', since) }

View file

@ -15,6 +15,7 @@ class GroupeInstructeur < ApplicationRecord
has_many :assign_tos, dependent: :destroy has_many :assign_tos, dependent: :destroy
has_many :instructeurs, through: :assign_tos has_many :instructeurs, through: :assign_tos
has_many :dossiers has_many :dossiers
has_many :deleted_dossiers
has_and_belongs_to_many :exports, dependent: :destroy has_and_belongs_to_many :exports, dependent: :destroy
has_and_belongs_to_many :bulk_messages, dependent: :destroy has_and_belongs_to_many :bulk_messages, dependent: :destroy