business registry contacts - endpoints for send status of contacts and receive confirmation

This commit is contained in:
olegphenomenon 2022-03-11 10:27:10 +02:00
parent a393854e1a
commit db012dd7da
7 changed files with 188 additions and 29 deletions

View file

@ -20,16 +20,34 @@ class RegistrantUser < User
def companies(company_register = CompanyRegister::Client.new)
return [] if ident.include?('-')
companies = company_register.representation_rights(citizen_personal_code: ident,
citizen_country_code: country.alpha3)
companies = update_contacts_before_receive(companies)
companies
company_register.representation_rights(citizen_personal_code: ident,
citizen_country_code: country.alpha3)
rescue CompanyRegister::NotAvailableError
return []
[]
end
def update_contacts_before_receive(companies)
def do_need_update_contact?
return { result: false, counter: 0 } if companies.blank?
counter = 0
companies.each do |company|
contacts = Contact.where(ident: company.registration_number, ident_country_code: 'EE')
next if contacts.blank?
contacts.each do |contact|
next if company.company_name == contact.name
counter += 1
end
end
return { result: true, counter: counter } if counter.positive?
{ result: false, counter: 0 }
end
def update_company_contacts
return [] if companies.blank?
companies.each do |company|