Class: Api::Dashboard::InventoriesController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Api::Dashboard::InventoriesController
- Defined in:
- app/controllers/api/dashboard/inventories_controller.rb
Instance Method Summary collapse
- #block ⇒ Object
- #create_or_update ⇒ Object
- #index ⇒ Object
- #inventory_template ⇒ Object
- #override_report ⇒ Object
Methods inherited from BaseController
#current_user, #identity_cache_memoization, #restaurants, #set_options
Methods included from LogrageCustomLogger
Methods included from ControllerHelpers
#check_boolean_param, #get_banners, #inventory_params, #reservation_params
Methods included from ResponseCacheConcern
Instance Method Details
#block ⇒ Object
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/api/dashboard/inventories_controller.rb', line 20 def block start_time = Time.zone.parse "#{valid_params[:start_date]} #{valid_params[:start_time]}" end_time = Time.zone.parse "#{valid_params[:end_date]} #{valid_params[:end_time]}" if start_time >= end_time render json: { success: false, message: 'Please provide valid time' }, status: :unprocessable_entity return end if valid_params[:reason].blank? render json: { success: false, message: 'Please provide the reason' }, status: :unprocessable_entity return end success = true = '' ActiveRecord::Base.transaction do restaurants.each do |restaurant| next if restaurant.use_third_party_inventory? operation = InventoryUpdater.call({ restaurant_id: restaurant.id, start_date: valid_params[:start_date].to_date, end_date: valid_params[:end_date].to_date, start_time: valid_params[:start_time], end_time: valid_params[:end_time], quantity_available: 0, reason: valid_params[:reason], }, 'settings' => { notify_staff: true, }) if operation.success? = operation['result.success_message'] else success = false = operation['result.fail_message'] raise ActiveRecord::Rollback end end end if success render json: { success: true, message: .presence } else render json: { success: false, message: () }, status: :unprocessable_entity end rescue ArgumentError, NoMethodError => e APMErrorHandler.report e render json: { success: false, message: 'Invalid date or time' }, status: :unprocessable_entity end |
#create_or_update ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/api/dashboard/inventories_controller.rb', line 70 def create_or_update if valid_params[:quantity_available].to_i < 1 render json: { success: false, message: 'You cannot edit alotment to "0" please use block inventory button' }, status: :unprocessable_entity return end success = true = '' ActiveRecord::Base.transaction do restaurants.each do |restaurant| next if restaurant.use_third_party_inventory? operation = InventoryUpdater.call(restaurant_id: restaurant.id, start_date: valid_params[:start_date].to_date, end_date: valid_params[:end_date].to_date, start_time: valid_params[:start_time], end_time: valid_params[:end_time], quantity_available: valid_params[:quantity_available]) if operation.success? = operation['result.success_message'] else success = false = operation['result.fail_message'] raise ActiveRecord::Rollback end end end if success render json: { success: true, message: } else render json: { success: false, message: () }, status: :unprocessable_entity end end |
#index ⇒ Object
4 5 6 7 |
# File 'app/controllers/api/dashboard/inventories_controller.rb', line 4 def index @date = params[:date].try(:to_date) || Date.today render json: Inventory.get_all_including_used_seats(restaurants.first.id, @date) end |
#inventory_template ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'app/controllers/api/dashboard/inventories_controller.rb', line 106 def inventory_template # create inventory template and generate schedule for dine_in and delivery service = RestaurantService::UpdateInventory.new(inventory_templates_param, restaurants.first) update_inventory = service.execute if update_inventory.success? render json: { success: true, message: update_inventory. } else render_error(update_inventory, :unprocessable_entity) end end |
#override_report ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'app/controllers/api/dashboard/inventories_controller.rb', line 9 def override_report updated_inventories = UpdatedInventory.includes(restaurant: :translations).where(restaurant_id: restaurants.ids) filter_params = params.fetch(:filter, {}) updated_inventories = Api::Dashboard::UpdatedInventoryFilter.new(updated_inventories) updated_inventories.filter(filter_params) pagy, updated_inventories = pagy(updated_inventories.to_collections) json = Api::Dashboard::UpdatedInventorySerializer.new(updated_inventories, (pagy)).as_json render json: json, status: :ok end |