Class: PartnerService::Inventories::DetailUpdaterService
- Inherits:
-
Object
- Object
- PartnerService::Inventories::DetailUpdaterService
- Defined in:
- app/services/partner_service/inventories/detail_updater_service.rb
Overview
Service class to update inventory details for one or more restaurants. Handles validation, processing inventory updates, and error handling.
Instance Method Summary collapse
-
#call ⇒ Hash
Executes the inventory update process.
-
#initialize(current_staff, params) ⇒ DetailUpdaterService
constructor
Initializes the service with the current staff and parameters for inventory updates.
Constructor Details
#initialize(current_staff, params) ⇒ DetailUpdaterService
Initializes the service with the current staff and parameters for inventory updates.
10 11 12 13 14 |
# File 'app/services/partner_service/inventories/detail_updater_service.rb', line 10 def initialize(current_staff, params) @current_staff = current_staff @params = params @change_tracker = PartnerService::ChangeTracker.new(current_staff) end |
Instance Method Details
#call ⇒ Hash
Executes the inventory update process.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/services/partner_service/inventories/detail_updater_service.rb', line 20 def call validate_time! restaurants = find_restaurants results = restaurants.map do |restaurant| next third_party_inventory_response(restaurant) if restaurant.use_third_party_inventory? @change_tracker.track_update_inventory(@params, restaurant.id) operation = InventoryUpdater.call( restaurant_id: restaurant.id, start_date: start_date, end_date: end_date, start_time: inventory_params[:start_time], end_time: inventory_params[:end_time], quantity_available: inventory_params[:quantity_available], ) if operation.success? @change_tracker.notify_managers restaurant end build_response(restaurant, operation) end format_response(results) rescue ActiveRecord::RecordNotFound => e { success: false, message: "Restaurant not found: #{e.}" } rescue ArgumentError => e { success: false, message: "Invalid parameter: #{e.}" } rescue NotAuthorized { success: false, message: 'Not authorized to update inventory' } rescue StandardError => e { success: false, message: e. } end |