mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 05:05:45 +02:00
parent
8c4e6f1656
commit
83f8a9fb6a
44 changed files with 530 additions and 610 deletions
|
@ -30,15 +30,6 @@ module Api
|
|||
header.gsub(pattern, '') if header&.match(pattern)
|
||||
end
|
||||
|
||||
def associated_domains(user)
|
||||
country_code, ident = user.registrant_ident.split('-')
|
||||
|
||||
BusinessRegistryCache.fetch_associated_domains(ident, country_code)
|
||||
rescue Soap::Arireg::NotAvailableError => error
|
||||
Rails.logger.fatal("[EXCEPTION] #{error}")
|
||||
user.domains
|
||||
end
|
||||
|
||||
def authenticate
|
||||
decryptor = AuthTokenDecryptor.create_with_defaults(bearer_token)
|
||||
decryptor.decrypt_token
|
||||
|
|
|
@ -4,8 +4,6 @@ module Api
|
|||
module V1
|
||||
module Registrant
|
||||
class ContactsController < ::Api::V1::Registrant::BaseController
|
||||
before_action :set_contacts_pool
|
||||
|
||||
def index
|
||||
limit = params[:limit] || 200
|
||||
offset = params[:offset] || 0
|
||||
|
@ -20,8 +18,8 @@ module Api
|
|||
status: :bad_request) && return
|
||||
end
|
||||
|
||||
@contacts = @contacts_pool.limit(limit).offset(offset)
|
||||
serialized_contacts = @contacts.map do |item|
|
||||
contacts = current_user_contacts.limit(limit).offset(offset)
|
||||
serialized_contacts = contacts.map do |item|
|
||||
serializer = Serializers::RegistrantApi::Contact.new(item)
|
||||
serializer.to_json
|
||||
end
|
||||
|
@ -30,7 +28,7 @@ module Api
|
|||
end
|
||||
|
||||
def show
|
||||
@contact = @contacts_pool.find_by(uuid: params[:uuid])
|
||||
@contact = current_user_contacts.find_by(uuid: params[:uuid])
|
||||
|
||||
if @contact
|
||||
render json: @contact
|
||||
|
@ -40,7 +38,7 @@ module Api
|
|||
end
|
||||
|
||||
def update
|
||||
contact = @contacts_pool.find_by!(uuid: params[:uuid])
|
||||
contact = current_user_contacts.find_by!(uuid: params[:uuid])
|
||||
contact.name = params[:name] if params[:name].present?
|
||||
contact.email = params[:email] if params[:email].present?
|
||||
contact.phone = params[:phone] if params[:phone].present?
|
||||
|
@ -97,22 +95,10 @@ module Api
|
|||
|
||||
private
|
||||
|
||||
def set_contacts_pool
|
||||
country_code, ident = current_registrant_user.registrant_ident.to_s.split '-'
|
||||
associated_domain_ids = begin
|
||||
BusinessRegistryCache.fetch_by_ident_and_cc(ident, country_code).associated_domain_ids
|
||||
end
|
||||
|
||||
available_contacts_ids = begin
|
||||
DomainContact.where(domain_id: associated_domain_ids).pluck(:contact_id) |
|
||||
Domain.where(id: associated_domain_ids).pluck(:registrant_id)
|
||||
end
|
||||
|
||||
@contacts_pool = Contact.where(id: available_contacts_ids)
|
||||
rescue Soap::Arireg::NotAvailableError => error
|
||||
Rails.logger.fatal("[EXCEPTION] #{error}")
|
||||
render json: { errors: [{ base: ['Business Registry not available'] }] },
|
||||
status: :service_unavailable and return
|
||||
def current_user_contacts
|
||||
current_registrant_user.contacts
|
||||
rescue CompanyRegister::NotAvailableError
|
||||
current_registrant_user.direct_contacts
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ module Api
|
|||
status: :bad_request) && return
|
||||
end
|
||||
|
||||
@domains = associated_domains(current_registrant_user).limit(limit).offset(offset)
|
||||
@domains = current_user_domains.limit(limit).offset(offset)
|
||||
|
||||
serialized_domains = @domains.map do |item|
|
||||
serializer = Serializers::RegistrantApi::Domain.new(item)
|
||||
|
@ -29,8 +29,7 @@ module Api
|
|||
end
|
||||
|
||||
def show
|
||||
domain_pool = associated_domains(current_registrant_user)
|
||||
@domain = domain_pool.find_by(uuid: params[:uuid])
|
||||
@domain = current_user_domains.find_by(uuid: params[:uuid])
|
||||
|
||||
if @domain
|
||||
serializer = Serializers::RegistrantApi::Domain.new(@domain)
|
||||
|
@ -39,6 +38,14 @@ module Api
|
|||
render json: { errors: [{ base: ['Domain not found'] }] }, status: :not_found
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_user_domains
|
||||
current_registrant_user.domains
|
||||
rescue CompanyRegister::NotAvailableError
|
||||
current_registrant_user.direct_domains
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue