diff --git a/app/controllers/api/customers_controller.rb b/app/controllers/api/customers_controller.rb index 2adc7c8a..d788ee06 100755 --- a/app/controllers/api/customers_controller.rb +++ b/app/controllers/api/customers_controller.rb @@ -10,6 +10,26 @@ class Api::CustomersController < ActionController::API @customer = Customer.find_by(params[:id]) end + def create + return unless params[:name].present? && params[:email].present? && params[:contact_no].present? + @customer = Customer.new(name: params[:name], email: params[:email], contact_no: params[:contact_no]) + if @customer.save + status = true + else + status = false + end + render json: status + end + + def get_customer_by_phone + if @customer = Customer.find_by_contact_no(params[:contact_no]) + status = true + else + status = false + end + render json: status + end + #Show customer detail by Order item def get_customer_order @customer = Customer.find(params[:id]) diff --git a/app/uploaders/customer_image_uploader.rb b/app/uploaders/customer_image_uploader.rb index 77a133af..871d5a39 100644 --- a/app/uploaders/customer_image_uploader.rb +++ b/app/uploaders/customer_image_uploader.rb @@ -20,10 +20,11 @@ class CustomerImageUploader < CarrierWave::Uploader::Base end def filename + return unless original_filename.present? if Shop.current_shop.shop_code.nil? - "#{original_filename}" if original_filename.present? + "#{original_filename}" else - "#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present? + "#{Shop.current_shop.shop_code}_#{original_filename}" end end diff --git a/config/routes.rb b/config/routes.rb index 69c4e0ff..5fb08e4c 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -83,6 +83,8 @@ scope "(:locale)", locale: /en|mm/ do #Current active bookings resources :bookings, only: [:index, :show, :create, :update] resources :customers + # get customer by phone + get "get_customer_by_phone" => "customers#get_customer_by_phone" #get customer details by order items get "customers/get_order/:id" => "customers#get_customer_order"