Sha256: 187602c3e297229526a93a0f2d513c1a08555766a579ddfe51710e248c992006

Contents?: true

Size: 1.86 KB

Versions: 5

Compression:

Stored size: 1.86 KB

Contents

module Mks
  module Rate
    class ChargeableServicesController < ApplicationController
      before_action :set_chargeable_service, only: [:update]
      def index
        result = ChargeableService.includes(:service_delivery_unit).order(:name)
        render json: result
      end

      def create
        cs = ChargeableService.new(chargeable_service_params)
        if cs.save
          render json: Mks::Common::MethodResponse.success_response(cs, 'Chargeable service saved successfully !')
        else
          render json: Mks::Common::MethodResponse.failure_response(cs), status: :unprocessable_entity
        end
      end

      def update
        if @cs.update(chargeable_service_params)
          render json: Mks::Common::MethodResponse.success_response(@cs, 'Chargeable service updated successfully !')
        else
          render json: Mks::Common::MethodResponse.failure_response(@cs), status: :unprocessable_entity
        end
      end

      def sdu_services
        result = ChargeableService.where(service_delivery_unit_id: params[:id])
        render json: result
      end

      def filter
        search = "%#{params[:search].downcase}%"
        services = ChargeableService.joins(:service_delivery_unit)
                                           .where('lower(mks_rate_chargeable_services.name) LIKE ? OR lower(mks_rate_service_delivery_units.name) LIKE ?',
                                                  search, search)
        render json: ApplicationRecord.as_json(services)
      end

      private

      def chargeable_service_params
        params.require(:chargeable_service).permit(:id, :code, :name, :service_delivery_unit_id, :base_unit_id,
                                                   :utilization_unit_id, :service_type_id)
      end

      def set_chargeable_service
        @cs = ChargeableService.find(params[:id])
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mks_rate-1.0.5 app/controllers/mks/rate/chargeable_services_controller.rb
mks_rate-1.0.4 app/controllers/mks/rate/chargeable_services_controller.rb
mks_rate-1.0.3 app/controllers/mks/rate/chargeable_services_controller.rb
mks_rate-1.0.2 app/controllers/mks/rate/chargeable_services_controller.rb
mks_rate-1.0.1 app/controllers/mks/rate/chargeable_services_controller.rb