Repp: Contact create: validate identifier

This commit is contained in:
Karl Erik Õunapuu 2020-10-07 12:46:19 +03:00
parent d4628d52ba
commit 01004b8ed4
No known key found for this signature in database
GPG key ID: C9DD647298A34764
5 changed files with 67 additions and 19 deletions

View file

@ -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