graphql: possibility to filter dossiers by archived
This commit is contained in:
parent
eff6f9c09c
commit
c404f92107
3 changed files with 56 additions and 2 deletions
|
@ -264,6 +264,11 @@ type Demarche {
|
|||
"""
|
||||
after: String
|
||||
|
||||
"""
|
||||
Si présent, permet de filtrer les dossiers archivés ou non
|
||||
"""
|
||||
archived: Boolean
|
||||
|
||||
"""
|
||||
Returns the elements in the list that come before the specified cursor.
|
||||
"""
|
||||
|
|
|
@ -37,6 +37,7 @@ module Types
|
|||
argument :created_since, GraphQL::Types::ISO8601DateTime, required: false, description: "Dossiers déposés depuis la date."
|
||||
argument :updated_since, GraphQL::Types::ISO8601DateTime, required: false, description: "Dossiers mis à jour depuis la date."
|
||||
argument :state, Types::DossierType::DossierState, required: false, description: "Dossiers avec statut."
|
||||
argument :archived, Boolean, required: false, description: "Si présent, permet de filtrer les dossiers archivés ou non"
|
||||
end
|
||||
|
||||
field :champ_descriptors, [Types::ChampDescriptorType], null: false, method: :types_de_champ
|
||||
|
@ -54,13 +55,17 @@ module Types
|
|||
Loaders::Record.for(Service).load(object.service_id)
|
||||
end
|
||||
|
||||
def dossiers(updated_since: nil, created_since: nil, state: nil, order:)
|
||||
def dossiers(updated_since: nil, created_since: nil, state: nil, archived: nil, order:)
|
||||
dossiers = object.dossiers.state_not_brouillon.for_api_v2
|
||||
|
||||
if state.present?
|
||||
dossiers = dossiers.where(state: state)
|
||||
end
|
||||
|
||||
if !archived.nil?
|
||||
dossiers = dossiers.where(archived: archived)
|
||||
end
|
||||
|
||||
if updated_since.present?
|
||||
dossiers = dossiers.updated_since(updated_since).order_by_updated_at(order)
|
||||
else
|
||||
|
|
|
@ -12,7 +12,7 @@ describe API::V2::GraphqlController do
|
|||
dossier
|
||||
end
|
||||
let(:dossier1) { create(:dossier, :en_construction, :with_individual, procedure: procedure, en_construction_at: 1.day.ago) }
|
||||
let(:dossier2) { create(:dossier, :en_construction, :with_individual, procedure: procedure, en_construction_at: 3.days.ago) }
|
||||
let(:dossier2) { create(:dossier, :en_construction, :with_individual, :archived, procedure: procedure, en_construction_at: 3.days.ago) }
|
||||
let(:dossier_brouillon) { create(:dossier, :with_individual, procedure: procedure) }
|
||||
let(:dossiers) { [dossier2, dossier1, dossier] }
|
||||
let(:instructeur) { create(:instructeur, followed_dossiers: dossiers) }
|
||||
|
@ -171,6 +171,50 @@ describe API::V2::GraphqlController do
|
|||
})
|
||||
end
|
||||
end
|
||||
|
||||
context "filter archived dossiers" do
|
||||
let(:query) do
|
||||
"{
|
||||
demarche(number: #{procedure.id}) {
|
||||
id
|
||||
number
|
||||
dossiers(archived: #{archived_filter}) {
|
||||
nodes {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
}"
|
||||
end
|
||||
|
||||
context 'with archived=true' do
|
||||
let(:archived_filter) { 'true' }
|
||||
it "only archived dossiers should be returned" do
|
||||
expect(gql_errors).to eq(nil)
|
||||
expect(gql_data).to eq(demarche: {
|
||||
id: procedure.to_typed_id,
|
||||
number: procedure.id,
|
||||
dossiers: {
|
||||
nodes: [{ id: dossier2.to_typed_id }]
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
context 'with archived=false' do
|
||||
let(:archived_filter) { 'false' }
|
||||
it "only not archived dossiers should be returned" do
|
||||
expect(gql_errors).to eq(nil)
|
||||
expect(gql_data).to eq(demarche: {
|
||||
id: procedure.to_typed_id,
|
||||
number: procedure.id,
|
||||
dossiers: {
|
||||
nodes: [{ id: dossier1.to_typed_id }, { id: dossier.to_typed_id }]
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "dossier" do
|
||||
|
|
Loading…
Reference in a new issue