added updated method

This commit is contained in:
olegphenomenon 2021-10-25 16:15:10 +03:00
parent b0ca5ddec0
commit b0ed6167f5
2 changed files with 17 additions and 2 deletions

View file

@ -102,6 +102,7 @@ module Api
ident_type: 'priv', ident_country_code: country) ident_type: 'priv', ident_country_code: country)
return contact if contact return contact if contact
update_contacts_before_receive
Contact.find_by(uuid: uuid, ident_type: 'org', ident: company_codes, Contact.find_by(uuid: uuid, ident_type: 'org', ident: company_codes,
ident_country_code: country) ident_country_code: country)
@ -109,6 +110,21 @@ module Api
nil nil
end end
def update_contacts_before_receive
company_register = CompanyRegister::Client.new
companies = company_register.representation_rights(citizen_personal_code: current_registrant_user.ident,
citizen_country_code: current_registrant_user.country.alpha3)
companies.each do |c|
contact = Contact.find_by(ident: c.registration_number)
break if contact.blank?
contact.update(name: c.company_name) unless c.company_name == contact.name
end
rescue CompanyRegister::NotAvailableError
nil
end
def company_codes def company_codes
current_registrant_user.companies.collect(&:registration_number) current_registrant_user.companies.collect(&:registration_number)
end end

View file

@ -20,8 +20,7 @@ class RegistrantUser < User
def companies(company_register = CompanyRegister::Client.new) def companies(company_register = CompanyRegister::Client.new)
return [] if ident.include?('-') return [] if ident.include?('-')
p "++++++++++++++++++++++++++++++++++++++++" company_register.representation_rights(citizen_personal_code: ident,
p company_register.representation_rights(citizen_personal_code: ident,
citizen_country_code: country.alpha3) citizen_country_code: country.alpha3)
end end