Class: Logistics::Core::CarriersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/logistics/core/carriers_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/logistics/core/carriers_controller.rb', line 17

def create
  @carrier = Carrier.new(carrier_params)
  if @carrier.valid?
    @carrier.save
    @response = Mks::Common::MethodResponse.new(true, 'Carrier saved successfully !',nil,nil,nil);
    render json: @response
  else
    errors = Mks::Common::Util.error_messages @carrier, 'Carrier'
    @response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil)
    render json: @response
  end
end

#engaged_agentsObject



42
43
44
45
46
47
48
# File 'app/controllers/logistics/core/carriers_controller.rb', line 42

def engaged_agents
  carrier_id = params[:carrier_id]
  engaged_agents_id = CarrierAgent.select(:agent_id).where('carrier_id' =>carrier_id)
  agents = Agent.where(id: engaged_agents_id)
  @response = Mks::Common::MethodResponse.new(true, nil, agents, nil, nil)
  render json: @response
end

#indexObject



6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/logistics/core/carriers_controller.rb', line 6

def index
  @carrier = Carrier.all
  carrier_array =[]
  @carrier.each { |c|
    carrier_array.push({:id => c.id, :name => c.name, :email => c.email, :contact_telephone => c.contact_telephone,
                        :carrier_type_id => c.carrier_type_id, :carrier_type_name => c.carrier_type.name})
  }
  @response = Mks::Common::MethodResponse.new(true, nil, carrier_array, nil, nil)
  render json: @response
end

#unengaged_agentsObject



50
51
52
53
54
55
56
# File 'app/controllers/logistics/core/carriers_controller.rb', line 50

def unengaged_agents
  carrier_id = params[:carrier_id]
  engaged_agents = CarrierAgent.select(:agent_id).where('carrier_id' => carrier_id)
  unengaged_agents = Agent.where.not(id: engaged_agents)
  @response = Mks::Common::MethodResponse.new(true, nil, unengaged_agents, nil, nil)
  render json: @response
end

#updateObject



30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/logistics/core/carriers_controller.rb', line 30

def update
  if @carrier.update_attributes(carrier_params)
    @carrier.save
    @response = Mks::Common::MethodResponse.new(true, 'Carrier updated successfully !', nil, nil, nil)
    render json: @response
  else
    errors = Mks::Common::Util.error_messages @carrier, 'Carrier'
    @response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil)
    render json: @response
  end
end