add api for survey
This commit is contained in:
47
app/controllers/api/survey_controller.rb
Normal file
47
app/controllers/api/survey_controller.rb
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
class Api::SurveyController < Api::ApiController
|
||||||
|
skip_before_action :authenticate
|
||||||
|
|
||||||
|
def index
|
||||||
|
dining_facility = DiningFacility.find(params[:id])
|
||||||
|
survey_data = Survey.find_by_dining_name(dining_facility.name)
|
||||||
|
countries = Lookup.collection_of("country")
|
||||||
|
if !countries.nil? || !survey_data.nil?
|
||||||
|
render :json => { :status => true, :data => { :countries => countries, :survey_data => survey_data} }
|
||||||
|
else
|
||||||
|
render :json => { :status => true, :error_message => "There is no data" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
dining_facility = DiningFacility.find(params[:id])
|
||||||
|
cashier_zone = CashierTerminalByZone.find_by_zone_id(dining_facility.zone_id)
|
||||||
|
shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil)
|
||||||
|
|
||||||
|
if params[:survey_id]
|
||||||
|
survey = Survey.find(params[:survey_id])
|
||||||
|
else
|
||||||
|
survey = Survey.new
|
||||||
|
end
|
||||||
|
survey.dining_name = dining_facility.name
|
||||||
|
survey.shift_id = shift_by_terminal.id
|
||||||
|
survey.child = params[:child]
|
||||||
|
survey.adult = params[:adult]
|
||||||
|
survey.male = params[:male]
|
||||||
|
survey.female = params[:female]
|
||||||
|
survey.local = params[:local]
|
||||||
|
survey.created_by = current_login_employee.name
|
||||||
|
survey.total_customer = params[:total_customer]
|
||||||
|
survey.total_amount = params[:total_amount]
|
||||||
|
survey.foreigner = params[:foreigner].to_json
|
||||||
|
survey.save!
|
||||||
|
|
||||||
|
render :json => { :status => true }
|
||||||
|
end
|
||||||
|
|
||||||
|
# private
|
||||||
|
# def survey_params
|
||||||
|
# params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner,
|
||||||
|
# :dining_name,:created_by,:total_customer,:total_amount)
|
||||||
|
# end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -78,6 +78,8 @@ scope "(:locale)", locale: /en|mm/ do
|
|||||||
post "check_in" => "check_in_process#check_in_process"
|
post "check_in" => "check_in_process#check_in_process"
|
||||||
post "request_time" => "check_in_process#request_time"
|
post "request_time" => "check_in_process#request_time"
|
||||||
post "call_waiter" => "call_waiters#index"
|
post "call_waiter" => "call_waiters#index"
|
||||||
|
get "survey/:id" => "survey#index"
|
||||||
|
post "survey/:id" => "survey#create"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user