Class: SpreeCmCommissioner::OrganizerProfileEventQuery

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vendor_id:, section:, start_from_date: nil) ⇒ OrganizerProfileEventQuery

user_id: user ID, vendor_id: vendor ID, section: ‘upcoming’, ‘previous’ or ‘all’



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

def initialize(vendor_id:, section:, start_from_date: nil)
  @vendor_id = vendor_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/organizer_profile_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/organizer_profile_event_query.rb', line 3

def start_from_date
  @start_from_date
end

#vendor_idObject (readonly)

Returns the value of attribute vendor_id.



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

def vendor_id
  @vendor_id
end

Instance Method Details

#eventsObject



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

def events
  taxons = Spree::Taxon.includes(:vendor).where(vendor_id: vendor_id, depth: 1)

  case section
  when 'upcoming'
    taxons.where('to_date >= ?', start_from_date)
          .order(from_date: :asc)
  when 'previous'
    taxons.where('to_date < ?', start_from_date)
          .order(to_date: :desc)
  else
    taxons.order(from_date: :asc)
  end
end