Class: Tagging::AcceptVoucherTagWorker

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

Instance Method Summary collapse

Methods inherited from ApplicationWorker

unlimited_retry

Instance Method Details

#perform(restaurant_id) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/workers/tagging/accept_voucher_tag_worker.rb', line 3

def perform(restaurant_id)
  restaurant = Restaurant.fetch restaurant_id
  restaurant_tag = RestaurantTag.find_by!(title_en: 'Admin:Accept Gift Cards')

  packages = restaurant.restaurant_packages.map(&:package)
  package_accept_voucher = packages.map(&:package_attr).select(&:accept_voucher).present?

  if package_accept_voucher
    data = RestaurantTagsRestaurant.new restaurant_id: restaurant.id, restaurant_tag_id: restaurant_tag.id
    RestaurantTagsRestaurant.import! [data], on_duplicate_key_update: %i[restaurant_id restaurant_tag_id], raise_error: true
  else
    restaurant_tag.restaurants.delete restaurant
  end
  restaurant.refresh_view_cache_key
end