diff --git a/app/graph/types/team_type.rb b/app/graph/types/team_type.rb index 2d91c95ea..94a9b58c4 100644 --- a/app/graph/types/team_type.rb +++ b/app/graph/types/team_type.rb @@ -402,6 +402,8 @@ def statistics(period:, language: nil, platform: nil) TeamStatistics.new(object, period, language, platform) end + field :statistics_platforms, [GraphQL::Types::String], null: true, description: 'List of tipline platforms for which we have data.' + field :bot_query, [TiplineSearchResultType], null: true do argument :search_text, GraphQL::Types::String, required: true argument :threshold, GraphQL::Types::Float, required: false diff --git a/app/models/team.rb b/app/models/team.rb index 8d0287446..4b7193f98 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -635,6 +635,11 @@ def get_dashboard_exported_data(filters, dashboard_type) data end + # Platforms for which statistics are available (e.g., at least one media request) + def statistics_platforms + TiplineRequest.joins(:project_media).where('project_medias.team_id' => self.id).group('platform').count.keys + end + # private # # Please add private methods to app/models/concerns/team_private.rb diff --git a/lib/relay.idl b/lib/relay.idl index 8317c62fb..a140a63d5 100644 --- a/lib/relay.idl +++ b/lib/relay.idl @@ -13417,6 +13417,11 @@ type Team implements Node { sources_count(keyword: String): Int spam_count: Int statistics(language: String, period: String!, platform: String): TeamStatistics + + """ + List of tipline platforms for which we have data. + """ + statistics_platforms: [String!] tag_texts( """ Returns the elements in the list that come after the specified cursor. diff --git a/public/relay.json b/public/relay.json index 19cc681da..d837c10ca 100644 --- a/public/relay.json +++ b/public/relay.json @@ -71006,6 +71006,28 @@ "isDeprecated": false, "deprecationReason": null }, + { + "name": "statistics_platforms", + "description": "List of tipline platforms for which we have data.", + "args": [ + + ], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, { "name": "tag_texts", "description": null, diff --git a/test/models/team_2_test.rb b/test/models/team_2_test.rb index 4c1f55a36..416b70242 100644 --- a/test/models/team_2_test.rb +++ b/test/models/team_2_test.rb @@ -1590,4 +1590,13 @@ def setup t = create_team assert_equal [], t.search_for_similar_articles('Test') end + + test "should return platforms for which statistics are available" do + t = create_team + pm = create_project_media team: t + assert_equal [], t.statistics_platforms + create_tipline_request team_id: t.id, platform: 'telegram', associated: pm + create_tipline_request team_id: t.id, platform: 'whatsapp', associated: pm + assert_equal ['telegram', 'whatsapp'], t.reload.statistics_platforms.sort + end end