Sha256: 869d2f548df1a8b9c2e4619d0efb999ac387acc943b01bbfc9a5c4c575fd6e1b
Contents?: true
Size: 1.78 KB
Versions: 39
Compression:
Stored size: 1.78 KB
Contents
# frozen_string_literal: true module Decidim module Meetings module Admin # A class used to find the Invites by their status status. class Invites < Rectify::Query # Syntactic sugar to initialize the class and return the queried objects. # # invites - the initial Invites relation that needs to be filtered. # query - query to filter invites # status - invite status to be used as a filter def self.for(invites, query = nil, status = nil) new(invites, query, status).query end # Initializes the class. # # invites - the initial Invites relation that need to be filtered # query - query to filter invites # status - invite status to be used as a filter def initialize(invites, query = nil, status = nil) @invites = invites @query = query @status = status end # List the invites by the different filters. def query @invites = filter_by_search(@invites) @invites = filter_by_status(@invites) @invites end private def filter_by_search(invites) return invites if @query.blank? invites.joins(:user).where( User.arel_table[:name].lower.matches("%#{@query}%").or(User.arel_table[:email].lower.matches("%#{@query}%")) ) end def filter_by_status(invites) case @status when "accepted" invites.where.not(accepted_at: nil) when "rejected" invites.where.not(rejected_at: nil) when "sent" invites.where.not(sent_at: nil).where(accepted_at: nil, rejected_at: nil) else invites end end end end end end
Version data entries
39 entries across 39 versions & 1 rubygems