From 17d9b21beba88b44abafbc7e9a12136521e2a4ad Mon Sep 17 00:00:00 2001 From: phyusin Date: Tue, 27 Nov 2018 11:56:56 +0630 Subject: [PATCH] add new check-in route --- .../api/check_in_process_controller.rb | 33 ++++++++++++++----- config/routes.rb | 1 + 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/check_in_process_controller.rb b/app/controllers/api/check_in_process_controller.rb index 3ac8a8af..ce0aaafd 100644 --- a/app/controllers/api/check_in_process_controller.rb +++ b/app/controllers/api/check_in_process_controller.rb @@ -2,8 +2,17 @@ class Api::CheckInProcessController < Api::ApiController # before_action :authenticate def check_in_time if params[:dining_id] - dining_facility = DiningFacility.find(params[:dining_id]) - booking = dining_facility.get_current_checkout_booking + dining_facility = DiningFacility.find(params[:dining_id]) + if params[:booking_id] + data = Booking.where("dining_facility_id = #{params[:dining_id]} AND booking_id = '#{params[:booking_id]}'") + if data.count > 0 + booking = data[0] + else + booking = nil + end + else + booking = dining_facility.get_current_checkout_booking + end if !booking.nil? # DiningFacility.check_in_booking(params[:dining_id]) @@ -12,18 +21,23 @@ class Api::CheckInProcessController < Api::ApiController #Send to background job for processing if ENV["SERVER_MODE"] == 'cloud' from = request.subdomain + "." + request.domain - else + else from = "" - end + end ActionCable.server.broadcast "check_in_booking_channel",table: table,from:from - + check_out_time = nil + extra_minutes = nil + alert_time_min = 0 check_in_time = booking.checkin_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") - check_out_time = booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") - - extra_minutes = (booking.checkout_at - booking.reserved_at) / 1.minutes + if booking.checkout_at + check_out_time = booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") + if booking.reserved_at + extra_minutes = (booking.checkout_at - booking.reserved_at) / 1.minutes + end + end lookup_checkout_time = Lookup.collection_of("checkout_alert_time") - alert_time_min = 0 + if !lookup_checkout_time.empty? now = Time.now.utc lookup_checkout_time.each do |checkout_time| @@ -38,6 +52,7 @@ class Api::CheckInProcessController < Api::ApiController else render :json => { :status => true } end + else render :json => { :status => false, :error_message => "No current booking!" } end diff --git a/config/routes.rb b/config/routes.rb index e68fc76d..e17892d8 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -77,6 +77,7 @@ scope "(:locale)", locale: /en|mm/ do namespace :origami do get "check_in/:dining_id" => "check_in_process#check_in_time" + get "check_in_time/:dining_id/:booking_id" => "check_in_process#check_in_time" post "check_in" => "check_in_process#check_in_process" post "request_time" => "check_in_process#request_time" post "call_waiter" => "call_waiters#index"