Skip to content

Commit

Permalink
include events in usage reports. #260
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed May 17, 2019
1 parent 0bf039e commit d697d5f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class UsageReportDatasetConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, subj_id: object.parent[:id], source_id: "datacite-usage").dig(:meta, "total").to_i
end
end
10 changes: 10 additions & 0 deletions app/graphql/types/usage_report_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ class UsageReportType < BaseObject
field :id, ID, null: false, description: "Usage report ID"
field :reporting_period, ReportingPeriodType, null: false, description: "Time period covered by the report"
field :date_created, String, null: false, description: "Date information was created"
field :datasets, UsageReportDatasetConnectionWithMetaType, null: false, description: "Datasets included in usage report", connection: true, max_page_size: 100 do
argument :first, Int, required: false, default_value: 25
end

def datasets(**args)
ids = Event.query(nil, subj_id: object[:id], source_id: "datacite-usage").fetch(:data, []).map do |e|
doi_from_url(e[:obj_id])
end
ElasticsearchLoader.for(Doi).load_many(ids)
end
end

0 comments on commit d697d5f

Please sign in to comment.