Skip to content

Commit

Permalink
correctly count deleted clients and providers. #118
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Oct 18, 2018
1 parent 0ef3c32 commit 07ba1e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions app/controllers/concerns/countable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def doi_count(client_id: nil, provider_id: nil)
response = Doi.query(nil, page: { number: 1, size: 0 })
end

response.results.total > 0 ? facet_by_year(response.response.aggregations.created.buckets) : nil
response.results.total > 0 ? facet_by_year(response.response.aggregations.created.buckets) : []
end

# cumulative count clients by year
Expand All @@ -21,19 +21,19 @@ def client_count(provider_id: nil)
if provider_id
response = Client.query(nil, provider_id: provider_id, include_deleted: true, page: { number: 1, size: 0 })
else
response = Client.query(nil, page: { number: 1, size: 0 })
response = Client.query(nil, include_deleted: true, page: { number: 1, size: 0 })
end

response.results.total > 0 ? facet_by_cumuative_year(response.response.aggregations.cumulative_years.buckets) : nil
response.results.total > 0 ? facet_by_cumuative_year(response.response.aggregations.cumulative_years.buckets) : []
end

# show provider count for admin
# count until the previous year if provider has been deleted
def provider_count(provider_id: nil)
return nil if provider_id

response = Provider.query(nil, page: { number: 1, size: 0 })
response.results.total > 0 ? facet_by_cumuative_year(response.response.aggregations.cumulative_years.buckets) : nil
response = Provider.query(nil, include_deleted: true, page: { number: 1, size: 0 })
response.results.total > 0 ? facet_by_cumuative_year(response.response.aggregations.cumulative_years.buckets) : []
end
end
end
4 changes: 2 additions & 2 deletions app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ def query(query, options={})
must << { range: { created: { gte: "#{options[:year].split(",").min}||/y", lte: "#{options[:year].split(",").max}||/y", format: "yyyy" }}} if options[:year].present?
must << { term: { region: options[:region].upcase }} if options[:region].present?
must << { term: { role_name: "ROLE_ALLOCATOR" }} unless options[:all_members]
must_not << { exists: { field: "deleted_at" }}
must_not << { exists: { field: "deleted_at" }} unless options[:include_deleted]
elsif self.name == "Client"
must << { range: { created: { gte: "#{options[:year].split(",").min}||/y", lte: "#{options[:year].split(",").max}||/y", format: "yyyy" }}} if options[:year].present?
must_not << { exists: { field: "deleted_at" }}
must_not << { exists: { field: "deleted_at" }} unless options[:include_deleted]
elsif self.name == "Doi"
must << { range: { published: { gte: "#{options[:year].split(",").min}||/y", lte: "#{options[:year].split(",").max}||/y", format: "yyyy" }}} if options[:year].present?
end
Expand Down

0 comments on commit 07ba1e3

Please sign in to comment.