Class: SpreeCmCommissioner::DashboardCrewEventQuery
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::DashboardCrewEventQuery
- Defined in:
- app/queries/spree_cm_commissioner/dashboard_crew_event_query.rb
Instance Attribute Summary collapse
-
#section ⇒ Object
readonly
Returns the value of attribute section.
-
#start_from_date ⇒ Object
readonly
Returns the value of attribute start_from_date.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #events ⇒ Object
-
#initialize(user:, section:, start_from_date: nil) ⇒ DashboardCrewEventQuery
constructor
user:, section: 'incoming | previous'.
Constructor Details
#initialize(user:, section:, start_from_date: nil) ⇒ DashboardCrewEventQuery
user:, section: 'incoming | previous'
6 7 8 9 10 |
# File 'app/queries/spree_cm_commissioner/dashboard_crew_event_query.rb', line 6 def initialize(user:, section:, start_from_date: nil) @user = user @section = section @start_from_date = start_from_date || Time.zone.now end |
Instance Attribute Details
#section ⇒ Object (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_date ⇒ Object (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 ⇒ Object (readonly)
Returns the value of attribute user.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/dashboard_crew_event_query.rb', line 3 def user @user end |
Instance Method Details
#events ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/queries/spree_cm_commissioner/dashboard_crew_event_query.rb', line 12 def events # Previous events are organizer-owned history; # operator roles are not meant to see them, only organizer (admins assign themselves # the organizer role explicitly if they need access). return Spree::Taxon.none if section == 'previous' && !user.organizer? 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 |