Class: AccountFindOrCreateService

Inherits:
BaseOperationService show all
Includes:
DefaultErrorContainer
Defined in:
app/services/account_find_or_create_service.rb

Overview

if given user data is not found on database, then system will create new user record and send email notification, and another notification but if already exist, then this service will return existing user record on database outcome of this service is [User] class

Instance Attribute Summary collapse

Attributes inherited from BaseOperationService

#outcome

Instance Method Summary collapse

Methods included from DefaultErrorContainer

#error, #error_message_simple, #merge_errors

Methods inherited from BaseOperationService

#success?

Constructor Details

#initialize(email, user_attributes) ⇒ AccountFindOrCreateService

Returns a new instance of AccountFindOrCreateService.

Parameters:

  • email (String)

    email of user

  • user_attributes (Hash)

    email, name, phone, password, line_id



14
15
16
17
18
19
# File 'app/services/account_find_or_create_service.rb', line 14

def initialize(email, user_attributes)
  @user = User.find_by(email: email)
  @params = user_attributes.slice(:name, :phone, :password, :line_id).merge(email: email).tap do |attr|
    attr[:name] = RemoveEmoji::Sanitize.call(attr[:name]) if attr[:name].present?
  end
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



11
12
13
# File 'app/services/account_find_or_create_service.rb', line 11

def user
  @user
end

Instance Method Details

#executeObject



21
22
23
24
25
26
# File 'app/services/account_find_or_create_service.rb', line 21

def execute
  return create_new_user if user.blank?
  self.outcome = user
  status_true
  true
end