Class: SpreeCmCommissioner::DashboardCrewEventQuery

Inherits:
Object
  • Object
show all
Defined in:
app/queries/spree_cm_commissioner/dashboard_crew_event_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id:, section:, start_from_date: nil) ⇒ DashboardCrewEventQuery

user_id:, section: ‘incoming | previous’



6
7
8
9
10
# File 'app/queries/spree_cm_commissioner/dashboard_crew_event_query.rb', line 6

def initialize(user_id:, section:, start_from_date: nil)
  @user_id = user_id
  @section = section
  @start_from_date = start_from_date || Time.zone.now
end

Instance Attribute Details

#sectionObject (readonly)

Returns the value of attribute section.



3
4
5
# File 'app/queries/spree_cm_commissioner/dashboard_crew_event_query.rb', line 3

def section
  @section
end

#start_from_dateObject (readonly)

Returns the value of attribute start_from_date.



3
4
5
# File 'app/queries/spree_cm_commissioner/dashboard_crew_event_query.rb', line 3

def start_from_date
  @start_from_date
end

#user_idObject (readonly)

Returns the value of attribute user_id.



3
4
5
# File 'app/queries/spree_cm_commissioner/dashboard_crew_event_query.rb', line 3

def user_id
  @user_id
end

Instance Method Details

#eventsObject



12
13
14
15
16
17
18
19
20
21
22
# File 'app/queries/spree_cm_commissioner/dashboard_crew_event_query.rb', line 12

def events
  taxons = Spree::Taxon.joins(:user_events).where(user_events: { user_id: user_id })

  if section == 'incoming'
    taxons.where('to_date >= ?', start_from_date)
          .order(from_date: :asc)
  else
    taxons.where('to_date < ?', start_from_date)
          .order(to_date: :desc)
  end
end