Sha256: 6fe21edf8bccbb381300ec56dafc10456ab37d65765de1e6f12c1ae45d6d158c

Contents?: true

Size: 1019 Bytes

Versions: 9

Compression:

Stored size: 1019 Bytes

Contents

module Logistics
  module Core
    class CarrierAgentsController < ApplicationController

      def index
        @carrierAgents = CarrierAgent.all
        carrier_agent_array = []
        @carrierAgents.each { |ca|
          carrier_agent_array.push({ :id => ca.id, :name => ca.carrier.name+' '+ca.agent.name})
        }
        @response = Mks::Common::MethodResponse.new(true, nil, carrier_agent_array, nil, nil)
        render json: @response
      end

      def create
        carriers = params[:carrier_agents]
        if carriers.count > 0
          carrier = Carrier.find carriers[0][:carrier_id]
        end
        carriers.each do |c|
          agent = Agent.find c[:agent_id]
          carrier.agents << agent
        end

        carrier.save
        response = Mks::Common::MethodResponse.new(true, 'Agent(s) associated successfully !')
        render json: response
      end

      def carrier_agent_params
        params.permit(:carrier_agents => [:carrier_id, :agent_id])
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
logistics_core-21.11.2 app/controllers/logistics/core/carrier_agents_controller.rb
logistics_core-21.11.1 app/controllers/logistics/core/carrier_agents_controller.rb
logistics_core-21.08.1 app/controllers/logistics/core/carrier_agents_controller.rb
logistics_core-21.03.1 app/controllers/logistics/core/carrier_agents_controller.rb
logistics_core-20.10.3 app/controllers/logistics/core/carrier_agents_controller.rb
logistics_core-20.10.2 app/controllers/logistics/core/carrier_agents_controller.rb
logistics_core-20.10.1 app/controllers/logistics/core/carrier_agents_controller.rb
logistics_core-20.9.1 app/controllers/logistics/core/carrier_agents_controller.rb
logistics_core-20.8.1 app/controllers/logistics/core/carrier_agents_controller.rb