Class: ScheduleWorkers::CalculateRestaurantInventoryWorker

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

Overview

typed: ignore frozen_string_literal: true

Instance Method Summary collapse

Methods inherited from ApplicationWorker

unlimited_retry

Instance Method Details

#performObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/workers/schedule_workers/calculate_restaurant_inventory_worker.rb', line 7

def perform
  Restaurant.active.not_expired.find_each do |restaurant|
    restaurant_info = RestaurantInfo.find_or_initialize_by(restaurant_id: restaurant.id)
    if restaurant.is_dine_in?
      has_dine_in_inventory = if restaurant.inventories.size.zero? || [restaurant.mon,
                                                                   restaurant.tue,
                                                                   restaurant.wed,
                                                                   restaurant.thu,
                                                                   restaurant.fri,
                                                                   restaurant.sat,
                                                                   restaurant.sun].compact.blank?
                                false
                              else
                                true
                              end

      restaurant_info.update(has_dine_in_inventory: has_dine_in_inventory)
    end
    if restaurant.is_take_away?
      has_delivery_inventory = if restaurant.inventory_take_aways.size.zero? || [restaurant.mon_take_away,
                                                                             restaurant.tue_take_away,
                                                                             restaurant.wed_take_away,
                                                                             restaurant.thu_take_away,
                                                                             restaurant.fri_take_away,
                                                                             restaurant.sat_take_away,
                                                                             restaurant.sun_take_away].compact.blank?
                                 false
                               else
                                 true
                               end
      restaurant_info.update(has_delivery_inventory: has_delivery_inventory)
    end
  end
end