Files
mozo-backend/app/controllers/users/orders_controller.rb
T
2015-09-16 11:50:55 +02:00

16 lines
554 B
Ruby

module Users
class OrdersController < Users::ApplicationController
respond_to :json
# /nested resource
def index
render json: {}, status: :not_found and return unless params[:list_id].present?
@list = List.find(params[:list_id])
render json: {}, status: :not_found and return unless @list.present? && Array.wrap(@list.user_ids).include?(current_user.id)
orders = @list.orders.include_relation(:product_orders)
render json: orders, include: %w[list user product_orders product_orders.order]
end
end
end