-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorders_controller.rb
More file actions
24 lines (19 loc) · 1020 Bytes
/
orders_controller.rb
File metadata and controls
24 lines (19 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Api::V1::OrdersController < ApiController
# before_action :get_device_table_mapping, only: [:create]
def create
#binding.pry
order_time = DateTime.strptime(params[:order_time].to_s,'%s')
@order = Order.create(name: params[:name], phone: params[:phone], address: params[:address], order_total: params[:order_total], order_time: order_time, restaurant_owner_id: @user.id)
order_detail = params[:order_detail]
order_detail.each do |detail|
OrderDetail.create(order_id: @order.id, menu_id: detail[:menu_id], quantity: detail[:quantity], item_price: detail[:item_price], item_name: detail[:item_name])
end
render :json => { message: "Order created successfully.", :status => 200 }
end
private
def get_device_table_mapping
device_id = params[:device_id]
@device = DeviceTableMapping.where(device_id: device_id, restaurant_owner_id: @user.id)
render :json => { message: "Invalid Device ID.", :status => 422 } unless @device.any?
end
end