Class: ReviewService::SecondHalfStep

Inherits:
ApplicationService show all
Defined in:
app/services/review_service/second_half_step.rb

Instance Attribute Summary collapse

Attributes inherited from ApplicationService

#object

Instance Method Summary collapse

Methods inherited from ApplicationService

#execute

Constructor Details

#initialize(review_id, email, password) ⇒ SecondHalfStep

Returns a new instance of SecondHalfStep.

Parameters:

  • review_id (Integer)
  • params (Hash)

    parameter for User



12
13
14
15
16
# File 'app/services/review_service/second_half_step.rb', line 12

def initialize(review_id, email, password)
  self.object = Review.find(review_id)
  @email = email
  @password = password
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



8
9
10
# File 'app/services/review_service/second_half_step.rb', line 8

def email
  @email
end

#passwordObject (readonly)

Returns the value of attribute password.



8
9
10
# File 'app/services/review_service/second_half_step.rb', line 8

def password
  @password
end

Instance Method Details

#execute!Object

Raises:

  • (ActiveRecord::ActiveRecordError)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/services/review_service/second_half_step.rb', line 18

def execute!
  success = false
  ActiveRecord::Base.transaction do
    registration_service = UserRegistration::UsingPassword.new(payload)
    unless registration_service.save
      object.errors.add(:base, registration_service.full_error_message)
      raise ActiveRecord::ActiveRecordError, registration_service.full_error_message
    end
    self.user = registration_service.user
    update_reservation!
    update_review!

    ::Reward.create!(points_total: 10,
                     points_pending: 0,
                     description: 'Becoming hungry hub member',
                     user_id: user.id,
                     redeemed: false,
                     country_id: user.country_id)
    success = true
  end
  raise ActiveRecord::ActiveRecordError unless success

  ServiceResult.new data: user
end

#next_step_pathObject



43
44
45
46
# File 'app/services/review_service/second_half_step.rb', line 43

def next_step_path
  url_helper.booking_review_landing_page_path(review_id: object.encrypted_id, booking_id: reservation.encrypted_id,
                                              locale: MyLocaleManager.normalize_locale, customer: :member)
end