Class: Api::V5::InventorySummariesFilter
- Inherits:
-
Object
- Object
- Api::V5::InventorySummariesFilter
- Includes:
- PaginationConcernFilter
- Defined in:
- app/filters/api/v5/inventory_summaries_filter.rb
Overview
for package sorting feature
Instance Attribute Summary collapse
-
#restaurant ⇒ Object
Returns the value of attribute restaurant.
Instance Method Summary collapse
- #as_json ⇒ Object
- #cache_key ⇒ Object
-
#initialize(restaurant_id) ⇒ InventorySummariesFilter
constructor
A new instance of InventorySummariesFilter.
- #inventory_summary_data ⇒ Object
Methods included from PaginationConcernFilter
Constructor Details
#initialize(restaurant_id) ⇒ InventorySummariesFilter
Returns a new instance of InventorySummariesFilter.
11 12 13 |
# File 'app/filters/api/v5/inventory_summaries_filter.rb', line 11 def initialize(restaurant_id) self.restaurant = Restaurant.fetch restaurant_id end |
Instance Attribute Details
#restaurant ⇒ Object
Returns the value of attribute restaurant.
9 10 11 |
# File 'app/filters/api/v5/inventory_summaries_filter.rb', line 9 def restaurant @restaurant end |
Instance Method Details
#as_json ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/filters/api/v5/inventory_summaries_filter.rb', line 35 def as_json { data: inventory_summary_data, message: '', success: true } end |
#cache_key ⇒ Object
15 16 17 18 19 20 |
# File 'app/filters/api/v5/inventory_summaries_filter.rb', line 15 def cache_key inv_cache_key = InventorySummary.where(restaurant_id: restaurant.id) .where('date >= ?', Date.restaurant_today(restaurant)).cache_key "#{inv_cache_key}/enable:#{AdminSetting.enable_package_sort_feature}" end |
#inventory_summary_data ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/filters/api/v5/inventory_summaries_filter.rb', line 22 def inventory_summary_data InventorySummary.select('id, restaurant_package_id, SUM(total_seat_left) AS total_seat_left_package') .where(restaurant_id: restaurant.id) .where('date >= ?', Date.restaurant_today(restaurant)) .group('restaurant_package_id') .find_each.map do |inv_summary| { restaurant_package_id: inv_summary['restaurant_package_id'], total_seat_left_package: [inv_summary['total_seat_left_package'], 0].max } end end |