From 76a22884e516198edf0f2a99a4312b34d1a41a28 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Fri, 4 Oct 2019 22:16:37 +0200 Subject: [PATCH] adding missing fields for person --- ...person_dataset_connection_with_meta_type.rb | 18 ++++++++++++++++++ ...on_publication_connection_with_meta_type.rb | 18 ++++++++++++++++++ ...erson_software_connection_with_meta_type.rb | 18 ++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 app/graphql/types/person_dataset_connection_with_meta_type.rb create mode 100644 app/graphql/types/person_publication_connection_with_meta_type.rb create mode 100644 app/graphql/types/person_software_connection_with_meta_type.rb diff --git a/app/graphql/types/person_dataset_connection_with_meta_type.rb b/app/graphql/types/person_dataset_connection_with_meta_type.rb new file mode 100644 index 000000000..2351c43d1 --- /dev/null +++ b/app/graphql/types/person_dataset_connection_with_meta_type.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class PersonDatasetConnectionWithMetaType < 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, obj_id: https_to_http(object.parent.uid ? "https://orcid.org/#{object.parent.uid}" : nil || object.parent[:id]), citation_type: "Dataset-Person").results.total + end + + def https_to_http(url) + uri = Addressable::URI.parse(url) + uri.scheme = "http" if uri.present? + uri.to_s + end +end \ No newline at end of file diff --git a/app/graphql/types/person_publication_connection_with_meta_type.rb b/app/graphql/types/person_publication_connection_with_meta_type.rb new file mode 100644 index 000000000..45544c029 --- /dev/null +++ b/app/graphql/types/person_publication_connection_with_meta_type.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class PersonPublicationConnectionWithMetaType < 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, obj_id: https_to_http(object.parent.uid ? "https://orcid.org/#{object.parent.uid}" : nil || object.parent[:id]), citation_type: "Person-ScholarlyArticle").results.total + end + + def https_to_http(url) + uri = Addressable::URI.parse(url) + uri.scheme = "http" if uri.present? + uri.to_s + end +end diff --git a/app/graphql/types/person_software_connection_with_meta_type.rb b/app/graphql/types/person_software_connection_with_meta_type.rb new file mode 100644 index 000000000..c922332da --- /dev/null +++ b/app/graphql/types/person_software_connection_with_meta_type.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class PersonSoftwareConnectionWithMetaType < 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, obj_id: https_to_http(object.parent.uid ? "https://orcid.org/#{object.parent.uid}" : nil || object.parent[:id]), citation_type: "Person-SoftwareSourceCode").results.total + end + + def https_to_http(url) + uri = Addressable::URI.parse(url) + uri.scheme = "http" if uri.present? + uri.to_s + end +end