module Users class OrdersController < Users::ApplicationController respond_to :json # Used by the user Ember app # POST /user/orders def create # render json: {}, status: :unprocessable_entity and return unless params[:order].present? && params[:order][:product_orders].present? if list = current_user.active_list render json: {}, status: :not_acceptable and return unless list.supplier.open? else #TODO: More logic about creating a new list!!!!!, usercontroller table_info should become irrelevant #NOTE: security bug here!!!!!! # - supplier.open? # - etc.... render json: {}, status: :unprocessable_entity and return unless params[:table_id].present? table = Table.find(params[:table_id]) render json: {}, status: :not_acceptable and return unless table.supplier.open? if table.occupied? #render json: json_alert('messages.table_is_occupied', location: :join_occupied_table, location_params: {table_id: @table.id}) render json: {}, status: :not_acceptable and return end list = List.from_table( table, current_user ) end order = list.place_order product_orders: params[:product_orders], user: current_user render json: order, serializer: OrderSerializer #render nothing: true end end end