Sha256: 74250f290498fa83de87fd64d4b116ef31e08cdd1b38762c1960c17b3d56eae4

Contents?: true

Size: 1.35 KB

Versions: 9

Compression:

Stored size: 1.35 KB

Contents

module Logistics
  module Core
    class ContractServicesController < ApplicationController
      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

      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

      private

      def contract_service_params
        params.permit(services: [:chargeable_service_id, :contract_id, :chargeable_service_unit_of_charge_id,
                                 :unit_of_charge_id, :service_delivery_unit_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/contract_services_controller.rb
logistics_core-21.11.1 app/controllers/logistics/core/contract_services_controller.rb
logistics_core-21.08.1 app/controllers/logistics/core/contract_services_controller.rb
logistics_core-21.03.1 app/controllers/logistics/core/contract_services_controller.rb
logistics_core-20.10.3 app/controllers/logistics/core/contract_services_controller.rb
logistics_core-20.10.2 app/controllers/logistics/core/contract_services_controller.rb
logistics_core-20.10.1 app/controllers/logistics/core/contract_services_controller.rb
logistics_core-20.9.1 app/controllers/logistics/core/contract_services_controller.rb
logistics_core-20.8.1 app/controllers/logistics/core/contract_services_controller.rb