mirror of
https://github.com/internetee/registry.git
synced 2025-06-05 12:17:30 +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
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
contact = current_user_contacts.find_by(uuid: params[:uuid])
|
contact = representable_contact(params[:uuid])
|
||||||
links = params[:links] == 'true'
|
links = params[:links] == 'true'
|
||||||
|
|
||||||
if contact
|
if contact
|
||||||
|
@ -91,6 +91,22 @@ module Api
|
||||||
|
|
||||||
private
|
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
|
def current_user_contacts
|
||||||
current_registrant_user.contacts(representable: false)
|
current_registrant_user.contacts(representable: false)
|
||||||
rescue CompanyRegister::NotAvailableError
|
rescue CompanyRegister::NotAvailableError
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue