Class: Mks::Rate::ChargeableServicesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/mks/rate/chargeable_services_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



10
11
12
13
14
15
16
17
# File 'app/controllers/mks/rate/chargeable_services_controller.rb', line 10

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

#filterObject



32
33
34
35
36
37
38
# File 'app/controllers/mks/rate/chargeable_services_controller.rb', line 32

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

#indexObject



5
6
7
8
# File 'app/controllers/mks/rate/chargeable_services_controller.rb', line 5

def index
  result = ChargeableService.includes(:service_delivery_unit).order(:name)
  render json: result
end

#sdu_servicesObject



27
28
29
30
# File 'app/controllers/mks/rate/chargeable_services_controller.rb', line 27

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

#updateObject



19
20
21
22
23
24
25
# File 'app/controllers/mks/rate/chargeable_services_controller.rb', line 19

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