mirror of
https://github.com/internetee/registry.git
synced 2025-08-04 08:52:04 +02:00
Replaced address with local and international addr
This commit is contained in:
parent
fe54f327d9
commit
2655da4555
16 changed files with 208 additions and 57 deletions
|
@ -1,20 +1,47 @@
|
|||
class Address < ActiveRecord::Base
|
||||
LOCAL_TYPE_SHORT = 'loc'
|
||||
INTERNATIONAL_TYPE_SHORT = 'int'
|
||||
LOCAL_TYPE = 'LocalAddress'
|
||||
TYPES = [
|
||||
LOCAL_TYPE_SHORT,
|
||||
INTERNATIONAL_TYPE_SHORT
|
||||
]
|
||||
|
||||
belongs_to :contact
|
||||
belongs_to :country
|
||||
|
||||
#validates_inclusion_of :type, in: TYPES
|
||||
|
||||
class << self
|
||||
def extract_attributes ah, type=:create
|
||||
address_hash = {}
|
||||
address_hash = ({
|
||||
country_id: Country.find_by(iso: ah[:cc]).try(:id),
|
||||
city: ah[:city],
|
||||
street: ah[:street][0],
|
||||
street2: ah[:street][1],
|
||||
street3: ah[:street][2],
|
||||
zip: ah[:pc]
|
||||
}) if ah.is_a?(Hash)
|
||||
|
||||
address_hash.delete_if { |k, v| v.nil? }
|
||||
[ah].flatten.each do |pi|
|
||||
address_hash[local?(pi)] = addr_hash_from_params(pi)
|
||||
end
|
||||
|
||||
address_hash
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def local?(postal_info)
|
||||
return :local_address_attributes if postal_info[:type] == LOCAL_TYPE_SHORT
|
||||
:international_address_attributes
|
||||
end
|
||||
|
||||
def addr_hash_from_params(addr)
|
||||
return {} unless addr[:addr].is_a?(Hash)
|
||||
{
|
||||
name: addr[:name],
|
||||
org_name: addr[:org],
|
||||
country_id: Country.find_by(iso: addr[:addr][:cc]).try(:id),
|
||||
city: addr[:addr][:city],
|
||||
street: addr[:addr][:street][0],
|
||||
street2: addr[:addr][:street][1],
|
||||
street3: addr[:addr][:street][2],
|
||||
zip: addr[:addr][:pc]
|
||||
}.delete_if { |k, v| v.nil? }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,16 +6,18 @@ class Contact < ActiveRecord::Base
|
|||
|
||||
EPP_ATTR_MAP = {}
|
||||
|
||||
has_one :address
|
||||
has_one :local_address#, class_name: 'Address'#, foreign_key: 'local_address_id'
|
||||
has_one :international_address
|
||||
|
||||
has_many :domain_contacts
|
||||
has_many :domains, through: :domain_contacts
|
||||
|
||||
belongs_to :created_by, class_name: 'EppUser', foreign_key: :created_by_id
|
||||
belongs_to :updated_by, class_name: 'EppUser', foreign_key: :updated_by_id
|
||||
|
||||
accepts_nested_attributes_for :address
|
||||
accepts_nested_attributes_for :local_address, :international_address
|
||||
|
||||
validates_presence_of :code, :name, :phone, :email, :ident
|
||||
validates_presence_of :code, :phone, :email, :ident
|
||||
|
||||
validate :ident_must_be_valid
|
||||
|
||||
|
@ -36,6 +38,16 @@ class Contact < ActiveRecord::Base
|
|||
CONTACT_TYPE_ADMIN = 'admin'
|
||||
CONTACT_TYPES = [CONTACT_TYPE_TECH, CONTACT_TYPE_ADMIN]
|
||||
|
||||
#TEMP METHODS for transaction to STI
|
||||
def name
|
||||
international_address.name
|
||||
end
|
||||
|
||||
def address
|
||||
international_address
|
||||
end
|
||||
##
|
||||
|
||||
def ident_must_be_valid
|
||||
#TODO Ident can also be passport number or company registry code.
|
||||
#so have to make changes to validations (and doc/schema) accordingly
|
||||
|
@ -114,11 +126,6 @@ class Contact < ActiveRecord::Base
|
|||
email: ph[:email]
|
||||
}
|
||||
|
||||
contact_hash = contact_hash.merge({
|
||||
name: ph[:postalInfo][:name],
|
||||
org_name: ph[:postalInfo][:org]
|
||||
}) if ph[:postalInfo].is_a? Hash
|
||||
|
||||
contact_hash[:code] = ph[:id] if type == :create
|
||||
|
||||
contact_hash.delete_if { |k, v| v.nil? }
|
||||
|
|
3
app/models/international_address.rb
Normal file
3
app/models/international_address.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class InternationalAddress < Address
|
||||
|
||||
end
|
3
app/models/local_address.rb
Normal file
3
app/models/local_address.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class LocalAddress < Address
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue