mirror of
https://github.com/internetee/registry.git
synced 2025-06-05 12:17:30 +02:00
refactoring
This commit is contained in:
parent
e9d7b40136
commit
ca231620f1
3 changed files with 36 additions and 12 deletions
|
@ -104,7 +104,6 @@ module Api
|
|||
|
||||
Contact.find_by(uuid: uuid, ident_type: 'org', ident: company_codes,
|
||||
ident_country_code: country)
|
||||
|
||||
rescue CompanyRegister::NotAvailableError
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -21,29 +21,54 @@ class RegistrantUser < User
|
|||
return [] if ident.include?('-')
|
||||
|
||||
companies = company_register.representation_rights(citizen_personal_code: ident,
|
||||
citizen_country_code: country.alpha3)
|
||||
update_contacts_before_receive(companies)
|
||||
citizen_country_code: country.alpha3)
|
||||
|
||||
p "++++++++++++++++++++"
|
||||
log("+++++++++++++")
|
||||
log(companies)
|
||||
log("+++++++++++++")
|
||||
p companies
|
||||
p "+++++++++++++++++++++"
|
||||
companies = update_contacts_before_receive(companies)
|
||||
companies
|
||||
end
|
||||
|
||||
def log(msg)
|
||||
@log ||= Logger.new($stdout)
|
||||
@log.info(msg)
|
||||
end
|
||||
|
||||
def update_contacts_before_receive(companies)
|
||||
return if companies.blank?
|
||||
|
||||
companies.each do |c|
|
||||
contact = Contact.find_by(ident: c.registration_number, ident_country_code: "EE")
|
||||
break if contact.blank?
|
||||
# contact = Contact.find_by(ident: c.registration_number, ident_country_code: 'EE')
|
||||
contacts = Contact.where(ident: c.registration_number, ident_country_code: 'EE')
|
||||
|
||||
unless c.company_name == contact.name
|
||||
old_contact_name = contact.name
|
||||
contact.update(name: c.company_name)
|
||||
notify_registrar_data_updated(company_name: c.company_name, old_contact_name: old_contact_name, contact: contact)
|
||||
break if contacts.blank?
|
||||
|
||||
contacts.each do |co|
|
||||
next if c.company_name == co.name
|
||||
|
||||
update_company_name(contact: co, company: c)
|
||||
end
|
||||
end
|
||||
|
||||
return companies
|
||||
rescue CompanyRegister::NotAvailableError
|
||||
nil
|
||||
end
|
||||
|
||||
def update_company_name(contact:, company:)
|
||||
old_contact_name = contact.name
|
||||
contact.name = company.company_name
|
||||
contact.save(validate: false)
|
||||
|
||||
notify_registrar_data_updated(company_name: company.company_name,
|
||||
old_contact_name: old_contact_name,
|
||||
contact: contact)
|
||||
end
|
||||
|
||||
def notify_registrar_data_updated(company_name:, old_contact_name:, contact:)
|
||||
contact.registrar.notifications.create!(
|
||||
text: "#{old_contact_name} was changed to #{company_name}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue