16 lines
642 B
Ruby
16 lines
642 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: JSONAPI::Serializer.serialize(orders, serializer: Users::OrderSerializer, include: %w[list user product_orders product_orders.order], is_collection: true)
|
|
end
|
|
|
|
end
|
|
end
|