mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 17:28:18 +02:00
Story#116761157 - search by linked contacts in dynamic way
This commit is contained in:
parent
34ef156484
commit
d1e5312b98
3 changed files with 26 additions and 18 deletions
|
@ -172,6 +172,27 @@ class Contact < ActiveRecord::Base
|
|||
')
|
||||
end
|
||||
|
||||
def find_linked
|
||||
where('
|
||||
EXISTS(
|
||||
select 1 from domains d where d.registrant_id = contacts.id
|
||||
) OR EXISTS(
|
||||
select 1 from domain_contacts dc where dc.contact_id = contacts.id
|
||||
)
|
||||
')
|
||||
end
|
||||
|
||||
def filter_by_states in_states
|
||||
states = Array(in_states).dup
|
||||
scope = all
|
||||
|
||||
# all contacts has state ok, so no need to filter by it
|
||||
states.delete(OK)
|
||||
scope = scope.find_linked if states.delete(LINKED)
|
||||
scope = scope.where( "contacts.statuses @> ?::varchar[]", "{#{states.join(',')}}") if states.any?
|
||||
scope
|
||||
end
|
||||
|
||||
# To leave only new ones we need to check
|
||||
# if contact was at any time used in domain.
|
||||
# This can be checked by domain history.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue