module Mks module Edm class EquipmentLocationsController < ApplicationController before_action :set_equipment_location, only: [:update] def index render json: Mks::Common::MethodResponse.success_response(EquipmentLocation.all) end 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 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 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 def stores data = EquipmentLocation.joins(:location_type) .where('mks_edm_location_types.name = ?', 'Store') render json: Mks::Common::MethodResponse.success_response(data) end private def equipment_location_params params.require(:equipment_location).permit(:id, :code, :name, :description, :address, :location_type_id) end def set_equipment_location @el = EquipmentLocation.find(params[:id]) end end end end