Class: Logistics::Core::ContractServicesController

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

Instance Method Summary collapse

Instance Method Details

#associate_serviceObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/logistics/core/contract_services_controller.rb', line 11

def associate_service
  services = []
  ContractService.where(contract_id: params[:id]).delete_all
  params[:services].each do |s|
    services.push(ContractService.new({ chargeable_service_id: s[:chargeable_service_id], contract_id: s[:contract_id],
                                        chargeable_service_unit_of_charge_id: s[:chargeable_service_unit_of_charge_id],
                                        unit_of_charge_id: s[:unit_of_charge_id], service_delivery_unit_id: s[:service_delivery_unit_id]}))
  end
  services.each(&:save)
  response = Mks::Common::MethodResponse.new(true, 'Service(s) saved successfully !', nil, nil, nil)
  render json: response
end

#indexObject



4
5
6
7
8
9
# File 'app/controllers/logistics/core/contract_services_controller.rb', line 4

def index
  cs = ContractService.where(contract_id: params[:contract_id])
  data = ActiveModelSerializers::SerializableResource.new(cs).as_json
  response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil)
  render json: response
end