Module: Decidim::Core::HasTimestampInputFilter

Included in:
Blogs::PostInputFilter
Defined in:
decidim-core/lib/decidim/api/input_filters/has_timestamp_input_filter.rb

Class Method Summary collapse

Class Method Details

.date_to_iso8601(date, key) ⇒ Object


45
46
47
48
49
# File 'decidim-core/lib/decidim/api/input_filters/has_timestamp_input_filter.rb', line 45

def self.date_to_iso8601(date, key)
  Date.iso8601(date)
rescue StandardError
  raise GraphQL::ExecutionError, "Invalid date format for #{key}"
end

.included(child_class) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'decidim-core/lib/decidim/api/input_filters/has_timestamp_input_filter.rb', line 6

def self.included(child_class)
  child_class.argument :created_before,
                       type: GraphQL::Types::String,
                       description: "List result created **before** (and **excluding**) this date. Expected format `YYYY-MM-DD`",
                       required: false,
                       prepare: lambda { |date, _ctx|
                         proc do |model_class|
                           model_class.arel_table[:created_at].lt(date_to_iso8601(date, :createdBefore))
                         end
                       }
  child_class.argument :created_since,
                       type: GraphQL::Types::String,
                       description: "List result created after (and **including**) this date. Expected format `YYYY-MM-DD`",
                       required: false,
                       prepare: lambda { |date, _ctx|
                         proc do |model_class|
                           model_class.arel_table[:created_at].gteq(date_to_iso8601(date, :createdBefore))
                         end
                       }
  child_class.argument :updated_before,
                       type: GraphQL::Types::String,
                       description: "List result updated **before** (and **excluding**) this date. Expected format `YYYY-MM-DD`",
                       required: false,
                       prepare: lambda { |date, _ctx|
                         proc do |model_class|
                           model_class.arel_table[:updated_at].lt(date_to_iso8601(date, :updatedBefore))
                         end
                       }
  child_class.argument :updated_since,
                       type: GraphQL::Types::String,
                       description: "List result updated after (and **including**) this date. Expected format `YYYY-MM-DD`",
                       required: false,
                       prepare: lambda { |date, _ctx|
                         proc do |model_class|
                           model_class.arel_table[:updated_at].gteq(date_to_iso8601(date, :updatedBefore))
                         end
                       }
end