mirror of
https://github.com/internetee/registry.git
synced 2025-06-03 19:27:29 +02:00
Registrant API: Simplify authorized contact search query
This commit is contained in:
parent
1d1c336117
commit
f07f03f0f9
1 changed files with 17 additions and 1 deletions
|
@ -24,7 +24,7 @@ module Api
|
|||
end
|
||||
|
||||
def show
|
||||
contact = current_user_contacts.find_by(uuid: params[:uuid])
|
||||
contact = representable_contact(params[:uuid])
|
||||
links = params[:links] == 'true'
|
||||
|
||||
if contact
|
||||
|
@ -91,6 +91,22 @@ module Api
|
|||
|
||||
private
|
||||
|
||||
def representable_contact(uuid)
|
||||
country = current_registrant_user.country.alpha2
|
||||
contact = Contact.find_by(uuid: uuid, ident: current_registrant_user.ident,
|
||||
ident_type: 'priv', ident_country_code: country)
|
||||
return contact if contact
|
||||
|
||||
Contact.find_by(uuid: uuid, ident_type: 'org', ident: company_codes,
|
||||
ident_country_code: country)
|
||||
rescue CompanyRegister::NotAvailableError
|
||||
nil
|
||||
end
|
||||
|
||||
def company_codes
|
||||
current_registrant_user.companies.collect(&:registration_number)
|
||||
end
|
||||
|
||||
def current_user_contacts
|
||||
current_registrant_user.contacts(representable: false)
|
||||
rescue CompanyRegister::NotAvailableError
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue