mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 20:18:22 +02:00
Repp: Contact create: validate identifier
This commit is contained in:
parent
d4628d52ba
commit
01004b8ed4
5 changed files with 67 additions and 19 deletions
|
@ -1,15 +1,17 @@
|
|||
module Actions
|
||||
class ContactCreate
|
||||
attr_reader :contact, :legal_document
|
||||
attr_reader :contact, :legal_document, :ident
|
||||
|
||||
def initialize(contact, legal_document)
|
||||
def initialize(contact, legal_document, ident)
|
||||
@contact = contact
|
||||
@legal_document = legal_document
|
||||
@ident = ident
|
||||
end
|
||||
|
||||
def call
|
||||
maybe_remove_address
|
||||
maybe_attach_legal_doc
|
||||
validate_ident
|
||||
commit
|
||||
end
|
||||
|
||||
|
@ -23,6 +25,24 @@ module Actions
|
|||
contact.country_code = nil
|
||||
end
|
||||
|
||||
def validate_ident
|
||||
if ident.present? && ident[:ident_type].blank?
|
||||
contact.add_epp_error('2003', nil, 'ident_type', I18n.t('errors.messages.required_ident_attribute_missing'))
|
||||
@error = true
|
||||
end
|
||||
|
||||
if ident.present? && ident[:ident_type] != 'birthday' && ident[:ident_country_code].blank?
|
||||
contact.add_epp_error('2003', nil, 'ident_country_code', I18n.t('errors.messages.required_ident_attribute_missing'))
|
||||
@error = true
|
||||
end
|
||||
|
||||
identifier = ::Contact::Ident.new(code: ident[:ident], type: ident[:ident_type],
|
||||
country_code: ident[:ident_country_code])
|
||||
|
||||
identifier.validate
|
||||
contact.identifier = identifier
|
||||
end
|
||||
|
||||
def maybe_attach_legal_doc
|
||||
return unless legal_document
|
||||
|
||||
|
@ -36,8 +56,9 @@ module Actions
|
|||
end
|
||||
|
||||
def commit
|
||||
contact.generate_code
|
||||
return false if @error
|
||||
|
||||
contact.generate_code
|
||||
contact.save
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue