Files
mozo-backend/app/controllers/users/lists_controller.rb
T
2014-08-28 14:53:24 +02:00

29 lines
1.3 KiB
Ruby

module Users
class ListsController < Users::ApplicationController
def index
#lists = current_user.lists.include_relation(:supplier, :table)
lists = List.for_user(current_user, page: params[:page], per_page: params[:per_page].presence || 25)
#lists.include_relation(:supplier)
lists.reject!{|l| l.id == params[:exclude_list]} if params[:exclude_list].present?
lists.include_relation(:users, :orders, :supplier)
render json: lists, each_serializer: UserListSerializer, meta: {total_pages: lists.total_pages, page: lists.current_page} #, root: :lists
end
#EMBER
def current
list = current_user.active_list
render json: {}, status: :not_found and return unless list.present?
[list].include_relation(supplier: {product_categories: :products}, orders: :product_orders) # table also when it is a real array :)
render json: json_response(not_present: true) and return unless list.present?
render json: list, serializer: UserExtendedListSerializer
end
def show
list = List.find(params[:id])
[list].include_relation(supplier: {product_categories: :products}, orders: :product_orders) # table also when it is a real array :)
render json: list, serializer: UserExtendedListSerializer
end
end
end