Class: RestaurantCpt::Operations::SettingsInventorySource

Inherits:
Trailblazer::Operation
  • Object
show all
Defined in:
app/concepts/restaurant_cpt/operations/settings_inventory_source.rb

Instance Method Summary collapse

Instance Method Details

#remove_bistrochat_restaurant!(options) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/concepts/restaurant_cpt/operations/settings_inventory_source.rb', line 99

def remove_bistrochat_restaurant!(options, *)
  params = options['params']
  restaurant = options['model']

  return true if params.blank?

  begin
    remove_bistrochat_restaurant_transaction(params, restaurant)
  rescue StandardError => e
    restaurant.errors.add(:base, e.message)
    return false
  end

  true
end

#remove_tablecheck_restaurant!(options) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/concepts/restaurant_cpt/operations/settings_inventory_source.rb', line 76

def remove_tablecheck_restaurant!(options, *)
  params = options['params']
  restaurant = options['model']

  return true if params.blank?

  ActiveRecord::Base.transaction do
    if params['inv_source'] == ApiVendorV1::Constants::TABLECHECK_INV_SOURCE_NAME
      TablecheckRestaurant.where(restaurant_id: restaurant.id).
        where.not(shop_id: params['shop_id']).destroy_all
    else
      TablecheckRestaurant.where(restaurant_id: restaurant.id).destroy_all
    end

    true
  rescue StandardError => e
    restaurant.errors.add(:base, e.message)
    return false
  end

  true
end

#update_inv_source!(options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/concepts/restaurant_cpt/operations/settings_inventory_source.rb', line 19

def update_inv_source!(options, *)
  params = options['params']
  restaurant = options['model']

  return true if params.blank?

  return true if params['inv_source'] == restaurant.inventory_source&.inv_source.to_s

  ActiveRecord::Base.transaction do
    inv_source = InventorySource.where(inv_source: params['inv_source']).first
    restaurant.inventory_source = inv_source
    restaurant.save!
  rescue StandardError => e
    restaurant.errors.add(:base, e.message)
    APMErrorHandler.report e
    return false
  end

  true
end

#update_inv_source_restaurant!(options) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/concepts/restaurant_cpt/operations/settings_inventory_source.rb', line 40

def update_inv_source_restaurant!(options, *)
  params = options['params']
  restaurant = options['model']

  return true if params.blank?

  ActiveRecord::Base.transaction do
    case params['inv_source']
    when ApiVendorV1::Constants::HUNGRYHUB_INV_SOURCE_NAME
      true
    when ApiVendorV1::Constants::SEVEN_ROOMS_INV_SOURCE_NAME
      seven_rooms_restaurant = SevenRoomsRestaurant.find_or_initialize_by(restaurant_id: restaurant.id)
      seven_rooms_restaurant.update!(venue_id: params['venue_id'])
    when ApiVendorV1::Constants::TABLECHECK_INV_SOURCE_NAME
      tablecheck_restaurant = TablecheckRestaurant.find_or_initialize_by(restaurant_id: restaurant.id)
      tablecheck_restaurant.update!(shop_id: params['shop_id'], shop_slug: params['shop_slug'])
    when ApiVendorV1::Constants::WEELOY_INV_SOURCE_NAME
      weeloy_restaurant = WeeloyRestaurant.find_or_initialize_by(restaurant_id: restaurant.id)
      weeloy_restaurant.update!(shop_id: params['shop_id'], shop_slug: params['shop_slug'])
    when ApiVendorV1::Constants::BISTROCHAT_INV_SOURCE_NAME
      bistrochat_restaurant = BistrochatRestaurant.find_or_initialize_by(restaurant_id: restaurant.id)
      bistrochat_restaurant.update!(shop_id: params['shop_id'], shop_slug: params['shop_slug'])
    when ApiVendorV1::Constants::MYMENU_INV_SOURCE_NAME
      my_menu_restaurant = MyMenuRestaurant.find_or_initialize_by(restaurant_id: restaurant.id)
      my_menu_restaurant.update!(shop_id: params['shop_id'], shop_slug: params['shop_slug'])
    else
      raise NotImplementedError
    end
  rescue StandardError => e
    restaurant.errors.add(:base, e.message)
    return false
  end

  true
end