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_id ⇒ Object
readonly
Returns the value of attribute user_id.
Instance Method Summary collapse
- #events ⇒ Object
-
#initialize(user_id:, section:, start_from_date: nil) ⇒ DashboardCrewEventQuery
constructor
user_id:, section: ‘incoming | previous’.
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
#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_id ⇒ Object (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
#events ⇒ Object
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 |