Class: Mks::Edm::EquipmentLocationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/mks/edm/equipment_locations_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/mks/edm/equipment_locations_controller.rb', line 10

def create
  el = EquipmentLocation.new(equipment_location_params)
  if el.valid?
    el.save
    res = Mks::Common::MethodResponse.success_response(el, 'Equipment location saved successfully !')
    render json: res
  else
    res = Mks::Common::MethodResponse.failure_response(el)
    render json: res, status: :unprocessable_entity
  end
end

#indexObject



6
7
8
# File 'app/controllers/mks/edm/equipment_locations_controller.rb', line 6

def index
  render json: Mks::Common::MethodResponse.success_response(EquipmentLocation.all)
end

#service_providersObject



32
33
34
35
36
# File 'app/controllers/mks/edm/equipment_locations_controller.rb', line 32

def service_providers
  data = EquipmentLocation.joins(:location_type)
                                       .where('mks_edm_location_types.name = ?', 'Service Provider')
  render json: Mks::Common::MethodResponse.success_response(data)
end

#storesObject



38
39
40
41
42
# File 'app/controllers/mks/edm/equipment_locations_controller.rb', line 38

def stores
  data = EquipmentLocation.joins(:location_type)
                            .where('mks_edm_location_types.name = ?', 'Store')
  render json: Mks::Common::MethodResponse.success_response(data)
end

#updateObject



22
23
24
25
26
27
28
29
30
# File 'app/controllers/mks/edm/equipment_locations_controller.rb', line 22

def update
  if @el.update(equipment_location_params)
    res = Mks::Common::MethodResponse.success_response(@el, 'Equipment location updated successfully !')
    render json: res
  else
    res = Mks::Common::MethodResponse.failure_response(@el)
    render json: res, status: :unprocessable_entity
  end
end