Updated

app/models/query / advanced_search.rb

C
112 lines of codes
9 methods
8.5 complexity/method
1 churn
76.23 complexity
100 duplications
class Query::AdvancedSearch
  1. Query::AdvancedSearch has no descriptive comment
def initialize(current_user, current_account, params) raise ArgumentError, 'current_user is required' if current_user.blank? raise ArgumentError, 'current_account is required' if current_account.blank? raise ArgumentError, 'params is required' if params.blank? @current_user = current_user @current_account = current_account @params = params @limit = 7 end def call
  1. Query::AdvancedSearch#call has approx 6 statements
case search_type when 'contact' { contacts: filter_contacts } when 'deal' { deals: filter_deals } when 'product' { products: filter_products } when 'pipeline' { pipelines: filter_pipelines } when 'activity' { activities: filter_activities } else { contacts: filter_contacts, deals: filter_deals, products: filter_products, pipelines: filter_pipelines, activities: filter_activities } end end private attr_reader :current_user, :current_account, :params, :limit def filter_contacts
  1. Similar code found in 4 nodes Locations: 0 1 2 3
scope = Contact if search_query.present?
  1. Query::AdvancedSearch tests 'search_query.present?' at least 5 times Locations: 0 1 2 3 4
pattern = "%#{search_query}%" scope = scope.where( 'full_name ILIKE :q OR email ILIKE :q OR phone ILIKE :q', q: pattern ) end scope.reorder('updated_at DESC').limit(limit) end def filter_deals
  1. Similar code found in 4 nodes Locations: 0 1 2 3
scope = Deal if search_query.present?
  1. Query::AdvancedSearch tests 'search_query.present?' at least 5 times Locations: 0 1 2 3 4
pattern = "%#{search_query}%" scope = scope.where( 'name ILIKE :q', q: pattern ) end scope.reorder('updated_at DESC').limit(limit) end def filter_products
  1. Similar code found in 4 nodes Locations: 0 1 2 3
scope = Product if search_query.present?
  1. Query::AdvancedSearch tests 'search_query.present?' at least 5 times Locations: 0 1 2 3 4
pattern = "%#{search_query}%" scope = scope.where( 'name ILIKE :q OR identifier ILIKE :q', q: pattern ) end scope.reorder('updated_at DESC').limit(limit) end def filter_pipelines
  1. Similar code found in 4 nodes Locations: 0 1 2 3
scope = Pipeline if search_query.present?
  1. Query::AdvancedSearch tests 'search_query.present?' at least 5 times Locations: 0 1 2 3 4
pattern = "%#{search_query}%" scope = scope.where( 'name ILIKE :q', q: pattern ) end scope.reorder('updated_at DESC').limit(limit) end def filter_activities scope = Event.activity if search_query.present?
  1. Query::AdvancedSearch tests 'search_query.present?' at least 5 times Locations: 0 1 2 3 4
pattern = "%#{search_query}%" scope = scope.where( 'title ILIKE :q', q: pattern ) end scope.reorder('updated_at DESC').limit(limit) end def search_type @search_type ||= params[:search_type]&.downcase end def search_query @search_query ||= params[:q].to_s.strip end end