Class: MHV::UserAccount::Creator
- Inherits:
-
Object
- Object
- MHV::UserAccount::Creator
- Defined in:
- app/services/mhv/user_account/creator.rb
Instance Attribute Summary collapse
-
#break_cache ⇒ Object
readonly
Returns the value of attribute break_cache.
-
#user_verification ⇒ Object
readonly
Returns the value of attribute user_verification.
Instance Method Summary collapse
- #create_mhv_user_account! ⇒ Object private
- #current_tou_agreement ⇒ Object private
- #email ⇒ Object private
- #icn ⇒ Object private
-
#initialize(user_verification:, break_cache: false) ⇒ Creator
constructor
A new instance of Creator.
- #log_error(error, type) ⇒ Object private
- #mhv_account_creation_response ⇒ Object private
- #mhv_client ⇒ Object private
- #perform ⇒ Object
- #user_account ⇒ Object private
- #validate! ⇒ Object private
Constructor Details
#initialize(user_verification:, break_cache: false) ⇒ Creator
Returns a new instance of Creator.
10 11 12 13 |
# File 'app/services/mhv/user_account/creator.rb', line 10 def initialize(user_verification:, break_cache: false) @user_verification = user_verification @break_cache = break_cache end |
Instance Attribute Details
#break_cache ⇒ Object (readonly)
Returns the value of attribute break_cache.
8 9 10 |
# File 'app/services/mhv/user_account/creator.rb', line 8 def break_cache @break_cache end |
#user_verification ⇒ Object (readonly)
Returns the value of attribute user_verification.
8 9 10 |
# File 'app/services/mhv/user_account/creator.rb', line 8 def user_verification @user_verification end |
Instance Method Details
#create_mhv_user_account! ⇒ Object (private)
32 33 34 35 36 37 |
# File 'app/services/mhv/user_account/creator.rb', line 32 def create_mhv_user_account! account = MHVUserAccount.new(mhv_account_creation_response) account.validate! MPIData.find(icn)&.destroy account end |
#current_tou_agreement ⇒ Object (private)
53 54 55 |
# File 'app/services/mhv/user_account/creator.rb', line 53 def current_tou_agreement @current_tou_agreement ||= user_account.terms_of_use_agreements.current.last end |
#email ⇒ Object (private)
49 50 51 |
# File 'app/services/mhv/user_account/creator.rb', line 49 def email @email ||= user_verification.user_credential_email&.credential_email end |
#icn ⇒ Object (private)
45 46 47 |
# File 'app/services/mhv/user_account/creator.rb', line 45 def icn @icn ||= user_account.icn end |
#log_error(error, type) ⇒ Object (private)
76 77 78 |
# File 'app/services/mhv/user_account/creator.rb', line 76 def log_error(error, type) Rails.logger.error("[MHV][UserAccount][Creator] #{type} error", error_message: error., icn:) end |
#mhv_account_creation_response ⇒ Object (private)
39 40 41 42 43 |
# File 'app/services/mhv/user_account/creator.rb', line 39 def mhv_account_creation_response tou_occurred_at = current_tou_agreement.created_at mhv_client.create_account(icn:, email:, tou_occurred_at:, break_cache:) end |
#mhv_client ⇒ Object (private)
61 62 63 |
# File 'app/services/mhv/user_account/creator.rb', line 61 def mhv_client MHV::AccountCreation::Service.new end |
#perform ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/services/mhv/user_account/creator.rb', line 15 def perform validate! create_mhv_user_account! rescue ActiveModel::ValidationError, Errors::ValidationError => e log_error(e, :validation) raise Errors::ValidationError, e. rescue Common::Client::Errors::Error => e log_error(e, :client) raise Errors::MHVClientError.new(e., e.body) rescue => e log_error(e, :creator) raise Errors::CreatorError, e. end |
#user_account ⇒ Object (private)
57 58 59 |
# File 'app/services/mhv/user_account/creator.rb', line 57 def user_account @user_account ||= user_verification.user_account end |
#validate! ⇒ Object (private)
65 66 67 68 69 70 71 72 73 74 |
# File 'app/services/mhv/user_account/creator.rb', line 65 def validate! errors = [ ('ICN must be present' if icn.blank?), ('Email must be present' if email.blank?), ('Current terms of use agreement must be present' if current_tou_agreement.blank?), ("Current terms of use agreement must be 'accepted'" unless current_tou_agreement&.accepted?) ].compact raise Errors::ValidationError, errors.join(', ') if errors.present? end |