Class: UserSpendingWorker

Inherits:
ApplicationWorker show all
Defined in:
app/workers/user_spending_worker.rb

Overview

typed: ignore Update User#total_spending after user made booking and arrived

Instance Method Summary collapse

Methods inherited from ApplicationWorker

unlimited_retry

Instance Method Details

#perform(reservation_id) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'app/workers/user_spending_worker.rb', line 4

def perform(reservation_id)
  reservation = Reservation.find(reservation_id)

  return false if reservation.cancelled? || reservation.user.blank? || !reservation.package? || !reservation.reached_goal?

  total_spending = reservation.user.total_spending.presence || 0
  reservation.package_obj.formatted_packages.map do |item|
    total_spending += Money.new(item['price_cents'], item['price_currency']).amount.to_i
  end
  reservation.user.update(total_spending: total_spending)
end