Class: Order::ContactLookup
- Inherits:
-
BaseService
- Object
- BaseService
- Order::ContactLookup
- Defined in:
- app/services/order/contact_lookup.rb
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
Methods inherited from BaseService
#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger
Constructor Details
This class inherits a constructor from BaseService
Instance Method Details
#process(order, params = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/services/order/contact_lookup.rb', line 7 def process(order, params={}) results = order.customer.contacts.active.order(:full_name) results_array = [] if params[:contact_id] results = results.where(id: params[:contact_id]) elsif search_term = params[:q].to_s.squish.presence results = results.where(Contact[:full_name].matches("%#{search_term}%")) end if results.present? results_array = results.uniq.map{|party| { id: party.id, text: "#{party.full_name} [#{party.id}]" } } elsif search_term results_array += [{ text: "Create New Contact"}] results_array += [{ display: "Create '#{search_term}' under #{order.customer.full_name}", id: "Customer|#{order.customer_id}|#{search_term}", text: search_term }] end Result.new(results: results_array, total_entries: results_array.size) end |