Fix ordering product issues by reverting emberization of product ordering

This commit is contained in:
2014-08-29 15:30:41 +02:00
parent aac47d3b51
commit ad4ad6bbb9
8 changed files with 54 additions and 50 deletions
+13 -5
View File
@@ -3,14 +3,21 @@ module Users
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?
converted_order = params[:order][:product_orders].each_with_object({}){|po, o| o[po[:product_id]] = po[:quantity] }
# render json: {}, status: :unprocessable_entity and return unless params[:order].present? && params[:order][:product_orders].present?
# converted_order = params[:order][:product_orders].each_with_object({}){|po, o| o[po[:product_id]] = po[:quantity] }
converted_order = params[:order]
table_id = params[:order].delete('table_id')
if list = current_user.active_list
render json: {}, status: :not_acceptable and return unless list.supplier.open?
else
render json: {}, status: :unprocessable_entity and return unless params[:order][:table_id].present?
table = Table.find(params[:order][:table_id])
#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 table_id.present?
table = Table.find(table_id)
render json: {}, status: :not_acceptable and return unless table.supplier.open?
if table.occupied?
@@ -21,7 +28,8 @@ module Users
list = List.from_table( table, current_user )
end
order = list.place_order products: converted_order, user: current_user
render json: order, serializer: OrderSerializer
# render json: order, serializer: OrderSerializer
render nothing: true
end
end
end