mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 20:18:22 +02:00
PostalInfo type checking for contact create
This commit is contained in:
parent
ad03165546
commit
678fd29c09
4 changed files with 24 additions and 7 deletions
|
@ -14,6 +14,23 @@ class Address < ActiveRecord::Base
|
|||
# validates_inclusion_of :type, in: TYPES
|
||||
|
||||
class << self
|
||||
|
||||
def validate_postal_info_types(parsed_frame)
|
||||
errors, used = [], []
|
||||
|
||||
parsed_frame.css('postalInfo').each do |pi|
|
||||
attr = pi.attributes['type'].try(:value)
|
||||
errors << { code: 2003, msg: I18n.t('errors.messages.attr_missing', key: 'type')} and next unless attr
|
||||
if !TYPES.include?(attr)
|
||||
errors << { code: 2005, msg: I18n.t('errors.messages.invalid_type'), value: { obj: 'type', val: attr }}
|
||||
next
|
||||
end
|
||||
errors << { code: 2005, msg: I18n.t('errors.messages.repeating_postal_info') } and next if used.include?(attr)
|
||||
used << attr
|
||||
end
|
||||
errors
|
||||
end
|
||||
|
||||
def extract_attributes(ah)
|
||||
address_hash = {}
|
||||
[ah].flatten.each do |pi|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue