diff options
Diffstat (limited to 'app/models/customer_relations/contact.rb')
-rw-r--r-- | app/models/customer_relations/contact.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/app/models/customer_relations/contact.rb b/app/models/customer_relations/contact.rb index cdb449e00bf..ded6ab8687a 100644 --- a/app/models/customer_relations/contact.rb +++ b/app/models/customer_relations/contact.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class CustomerRelations::Contact < ApplicationRecord + include Gitlab::SQL::Pattern + include Sortable include StripAttribute self.table_name = "customer_relations_contacts" @@ -39,6 +41,25 @@ class CustomerRelations::Contact < ApplicationRecord ']' end + # Searches for contacts with a matching first name, last name, email or description. + # + # This method uses ILIKE on PostgreSQL + # + # query - The search query as a String + # + # Returns an ActiveRecord::Relation. + def self.search(query) + fuzzy_search(query, [:first_name, :last_name, :email, :description], use_minimum_char_limit: false) + end + + def self.search_by_state(state) + where(state: state) + end + + def self.sort_by_name + order("last_name ASC, first_name ASC") + end + def self.find_ids_by_emails(group, emails) raise ArgumentError, "Cannot lookup more than #{MAX_PLUCK} emails" if emails.length > MAX_PLUCK |