Sha256: 84ae9c8e58f924967d30deac68ded18a8b40dc43cfa1c47eaada43333ffeb149

Contents?: true

Size: 1.32 KB

Versions: 19

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Decidim
  module Elections
    # A class used to find elections filtered by its state
    class FilteredElections < Decidim::Query
      # Syntactic sugar to initialize the class and return the queried objects.
      #
      # components - An array of Decidim::Component
      # start_at - A date to filter resources created after it
      # end_at - A date to filter resources created before it.
      def self.for(components, start_at = nil, end_at = nil)
        new(components, start_at, end_at).query
      end

      # Initializes the class.
      #
      # components - An array of Decidim::Component
      # start_at - A date to filter resources created after it
      # end_at - A date to filter resources created before it.
      def initialize(components, start_at = nil, end_at = nil)
        @components = components
        @start_at = start_at
        @end_at = end_at
      end

      # Finds the Projects scoped to an array of components and filtered
      # by a range of dates.
      def query
        elections = Decidim::Elections::Election.where(component: @components)
        elections = elections.where("created_at >= ?", @start_at) if @start_at.present?
        elections = elections.where("created_at <= ?", @end_at) if @end_at.present?
        elections
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
decidim-elections-0.28.4 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.27.9 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.28.3 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.27.8 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.28.2 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.27.7 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.28.1 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.27.6 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.28.0 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.27.5 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.28.0.rc5 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.28.0.rc4 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.27.4 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.27.3 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.27.2 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.27.1 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.27.0 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.27.0.rc2 app/queries/decidim/elections/filtered_elections.rb
decidim-elections-0.27.0.rc1 app/queries/decidim/elections/filtered_elections.rb