Skip to content

Commit

Permalink
Filter articles by "created" date. (#2208)
Browse files Browse the repository at this point in the history
Adding a new filter to the GraphQL fields `TeamType.articles` and `TeamType.articles_count`: "created" date.

Reference: CV2-5851.
  • Loading branch information
caiosba authored Feb 9, 2025
1 parent a6d1a86 commit ba5e8f8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/graph/types/team_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ def tipline_requests(from_timestamp:, to_timestamp:)
argument :tags, [GraphQL::Types::String, null: true], required: false, camelize: false
argument :language, [GraphQL::Types::String, null: true], required: false, camelize: false
argument :updated_at, GraphQL::Types::String, required: false, camelize: false # JSON
argument :created_at, GraphQL::Types::String, required: false, camelize: false # JSON
argument :text, GraphQL::Types::String, required: false, camelize: false # Search by text
argument :standalone, GraphQL::Types::Boolean, required: false, camelize: false # Not applied to any item (fact-checks only)
argument :publisher_ids, [GraphQL::Types::Int, null: true], required: false, camelize: false
Expand Down Expand Up @@ -347,6 +348,7 @@ def articles(**args)
argument :tags, [GraphQL::Types::String, null: true], required: false, camelize: false
argument :language, [GraphQL::Types::String, null: true], required: false, camelize: false
argument :updated_at, GraphQL::Types::String, required: false, camelize: false # JSON
argument :created_at, GraphQL::Types::String, required: false, camelize: false # JSON
argument :text, GraphQL::Types::String, required: false, camelize: false # Search by text
argument :standalone, GraphQL::Types::Boolean, required: false, camelize: false # Not applied to any item (fact-checks only)
argument :publisher_ids, [GraphQL::Types::Int, null: true], required: false, camelize: false
Expand Down
2 changes: 2 additions & 0 deletions app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ def filtered_explainers(filters = {})

# Filter by date
query = query.where(updated_at: Range.new(*format_times_search_range_filter(JSON.parse(filters[:updated_at]), nil))) unless filters[:updated_at].blank?
query = query.where(created_at: Range.new(*format_times_search_range_filter(JSON.parse(filters[:created_at]), nil))) unless filters[:created_at].blank?

# Filter by trashed
query = query.where(trashed: !!filters[:trashed])
Expand Down Expand Up @@ -529,6 +530,7 @@ def filtered_fact_checks(filters = {})

# Filter by date
query = query.where('fact_checks.updated_at' => Range.new(*format_times_search_range_filter(JSON.parse(filters[:updated_at]), nil))) unless filters[:updated_at].blank?
query = query.where('fact_checks.created_at' => Range.new(*format_times_search_range_filter(JSON.parse(filters[:created_at]), nil))) unless filters[:created_at].blank?

# Filter by publisher
query = query.where('fact_checks.publisher_id' => filters[:publisher_ids].to_a.map(&:to_i)) unless filters[:publisher_ids].blank?
Expand Down
3 changes: 2 additions & 1 deletion lib/relay.idl
Original file line number Diff line number Diff line change
Expand Up @@ -13187,6 +13187,7 @@ type Team implements Node {
Returns the elements in the list that come before the specified cursor.
"""
before: String
created_at: String

"""
Returns the first _n_ elements from the list.
Expand All @@ -13213,7 +13214,7 @@ type Team implements Node {
updated_at: String
user_ids: [Int]
): ArticleUnionConnection
articles_count(article_type: String, imported: Boolean, language: [String], publisher_ids: [Int], rating: [String], report_status: [String], standalone: Boolean, tags: [String], target_id: Int, text: String, trashed: Boolean = false, updated_at: String, user_ids: [Int]): Int
articles_count(article_type: String, created_at: String, imported: Boolean, language: [String], publisher_ids: [Int], rating: [String], report_status: [String], standalone: Boolean, tags: [String], target_id: Int, text: String, trashed: Boolean = false, updated_at: String, user_ids: [Int]): Int
available_newsletter_header_types: JsonStringType
avatar: String
bot_query(enableLanguageDetection: Boolean, enableLinkShortening: Boolean, maxNumberOfWords: Int, searchText: String!, shouldRestrictByLanguage: Boolean, threshold: Float, utmCode: String): [TiplineSearchResult!]
Expand Down
24 changes: 24 additions & 0 deletions public/relay.json
Original file line number Diff line number Diff line change
Expand Up @@ -69301,6 +69301,18 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "created_at",
"description": null,
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "text",
"description": null,
Expand Down Expand Up @@ -69494,6 +69506,18 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "created_at",
"description": null,
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "text",
"description": null,
Expand Down

0 comments on commit ba5e8f8

Please sign in to comment.