Module: Decidim::Core::HasPublishableInputFilter

Included in:
ComponentInputFilter, ParticipatorySpaceInputFilter
Defined in:
lib/decidim/api/input_filters/has_publishable_input_filter.rb

Class Method Summary collapse

Class Method Details

.date_to_iso8601(date, key) ⇒ Object



27
28
29
30
31
# File 'lib/decidim/api/input_filters/has_publishable_input_filter.rb', line 27

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
# File 'lib/decidim/api/input_filters/has_publishable_input_filter.rb', line 6

def self.included(child_class)
  child_class.argument :published_before,
                       type: GraphQL::Types::String,
                       description: "List result published **before** (and **excluding**) this date. Expected format `YYYY-MM-DD`",
                       required: false,
                       prepare: lambda { |date, _ctx|
                         proc do |model_class|
                           model_class.arel_table[:published_at].lt(date_to_iso8601(date, :publishedBefore))
                         end
                       }
  child_class.argument :published_since,
                       type: GraphQL::Types::String,
                       description: "List result published after (and **including**) this date. Expected format `YYYY-MM-DD`",
                       required: false,
                       prepare: lambda { |date, _ctx|
                         proc do |model_class|
                           model_class.arel_table[:published_at].gteq(date_to_iso8601(date, :publishedBefore))
                         end
                       }
end