diff --git a/app/controllers/public_controller.rb b/app/controllers/public_controller.rb index ac573a7..5983a52 100644 --- a/app/controllers/public_controller.rb +++ b/app/controllers/public_controller.rb @@ -4,11 +4,11 @@ class PublicController < ApplicationController include ApplicationHelper include OrderSessionHelper - skip_before_action :authenticate_user_from_token!, only: :recent_beverages - skip_before_action :authenticate_user!, only: :recent_beverages + skip_before_action :authenticate_user_from_token!, only: :recent + skip_before_action :authenticate_user!, only: :recent - def recent_beverages - orders = Order.recent_beverages + def recent + orders = Order.recent mapped_orders = orders.joins(:order_items => :product).map do |order| order.order_items.map do |order_item| product = order_item.product diff --git a/app/models/order.rb b/app/models/order.rb index d13f2ed..a6e5fe9 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -34,9 +34,7 @@ class Order < ApplicationRecord scope :pending, -> { where(created_at: Rails.application.config.call_api_after.ago..) } scope :final, -> { where(created_at: ..Rails.application.config.call_api_after.ago) } - scope :from_last_two_weeks, -> { where(created_at: 2.weeks.ago..Time.zone.now) } - scope :with_category, ->(category) { joins(:products).where(products: { category: category }).distinct } - scope :recent_beverages, -> { from_last_two_weeks.with_category("beverages") } + scope :recent, -> { where(created_at: 2.weeks.ago..Time.zone.now) } def to_sentence order_items.map do |oi| diff --git a/config/routes.rb b/config/routes.rb index 523c50c..153e4a4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -58,7 +58,7 @@ # Koelkast overview page get "overview" => "orders#overview", as: "orders" - get "recent_beverages" => "public#recent_beverages", as: "recent_beverages" + get "recent" => "public#recent", as: "recent" # Guest endpoints namespace :guest do