lib/production/interactors/resource_interactor.rb
# Add buttons to a plant resource
Add buttons to a plant resource
Add buttons to a plant resource
def add_buttons(id, params) 
      res = Dry::Schema.Params do
        required(:no_buttons).filled(:integer, gt?: 0, lt?: 11)
      end.call(params)
      return validation_failed_response(res) if res.failure?
      qty = res[:no_buttons]
      parent = plant_resource(id)
      btn_type_id = repo.get_id(:plant_resource_types, plant_resource_type_code: Crossbeams::Config::ResourceDefinitions::ROBOT_BUTTON)
      last_button, last_desc = repo.last_plant_button_code_and_desc(id)
      last_button ||= "#{parent[:plant_resource_code]}-B0"
      last_desc ||= "#{parent[:description]} Button 0"
      repo.transaction do
        qty.times do
          last_button = last_button.succ
          last_desc = last_desc.succ
          res = validate_plant_resource_params(plant_resource_type_id: btn_type_id, plant_resource_code: last_button, description: last_desc)
          repo.create_child_plant_resource(id, res, sys_code: nil)
        end
      end
      success_response("Added #{qty} button#{qty == 1 ? '' : 's'}")
    end
def add_buttons ( id , params ) res = Dry :: Schema . Params do required ( :no_buttons ) . filled ( :integer , gt? : 0 , lt? : 11 ) end . call ( params ) return validation_failed_response ( res ) if res . failure? qty = res [ :no_buttons ] parent = plant_resource ( id ) btn_type_id = repo . get_id ( :plant_resource_types , plant_resource_type_code : Crossbeams :: Config :: ResourceDefinitions :: ROBOT_BUTTON ) last_button , last_desc = repo . last_plant_button_code_and_desc ( id ) last_button ||= "#{parent[:plant_resource_code]}-B0" last_desc ||= "#{parent[:description]} Button 0" repo . transaction do qty . times do last_button = last_button . succ last_desc = last_desc . succ res = validate_plant_resource_params ( plant_resource_type_id : btn_type_id , plant_resource_code : last_button , description : last_desc ) repo . create_child_plant_resource ( id , res , sys_code : nil ) end end success_response ( "Added #{qty} button#{qty == 1 ? '' : 's'}" ) end
Add buttons to a plant resource
Add buttons to a plant resource
# rubocop:disable Metrics/AbcSize
id
<not_specific>
params
<not_specific>