Class: Logistics::Core::ServiceDeliveryUnitsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Logistics::Core::ServiceDeliveryUnitsController
- Defined in:
- app/controllers/logistics/core/service_delivery_units_controller.rb
Instance Method Summary collapse
- #chargeable_services ⇒ Object
- #create ⇒ Object
- #get_chargeable_service_name(cs_id) ⇒ Object
- #get_sdus_with_specific_services ⇒ Object
- #index ⇒ Object
- #unassigned_services ⇒ Object
-
#update ⇒ Object
PATCH/PUT /service_delivery_units/1 PATCH/PUT /service_delivery_units/1.json.
Instance Method Details
#chargeable_services ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/logistics/core/service_delivery_units_controller.rb', line 53 def chargeable_services cs_array = [] service_delivery_unit_id = params[:id] chargeable_services = ServiceDeliveryUnitChargeableService.where('service_delivery_unit_id' =>service_delivery_unit_id) chargeable_services.each { |cs| cs_array.push({:id =>cs.chargeable_service_id, :name => get_chargeable_service_name(cs.chargeable_service_id), :is_mandatory => cs.is_mandatory, sdu_cs_id: cs.id}) } @response = {:success => true, :message => '', :data => cs_array} render json: @response end |
#create ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/logistics/core/service_delivery_units_controller.rb', line 20 def create @service_delivery_unit = ServiceDeliveryUnit.new(model_params) if @service_delivery_unit.valid? @service_delivery_unit.save @response = {:success => true, :message => 'Service delivery unit saved successfully!', :data => @service_delivery_unit} render json: @response else errors = Mks::Common::Util.(@service_delivery_unit, 'Service delivery unit') response = Mks::Common::MethodResponse.new(false,nil,nil,errors,nil) render json: response end end |
#get_chargeable_service_name(cs_id) ⇒ Object
48 49 50 51 |
# File 'app/controllers/logistics/core/service_delivery_units_controller.rb', line 48 def get_chargeable_service_name(cs_id) cs = ChargeableService.find(cs_id) return cs.name end |
#get_sdus_with_specific_services ⇒ Object
73 74 75 76 77 78 79 |
# File 'app/controllers/logistics/core/service_delivery_units_controller.rb', line 73 def get_sdus_with_specific_services offer_request_id = params[:offer_request_id] type = params[:type] sdus = ServiceDeliveryUnit.get_sdus_with_specific_services(offer_request_id, type) response = Mks::Common::MethodResponse.new(true, nil, sdus, nil, nil) render json: response end |
#index ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/controllers/logistics/core/service_delivery_units_controller.rb', line 7 def index @sdus = ServiceDeliveryUnit.all service_delivery_units_array = [] @sdus.each { |sdu| service_delivery_units_array.push({:id => sdu.id, :code => sdu.code, :name => sdu.name, :address => sdu.address, :currency_id => sdu.currency_id, :currency_name => sdu.currency.name, :service_delivery_unit_type_id => sdu.service_delivery_unit_type_id, :type_name => sdu.service_delivery_unit_type.name }) } @response = {:success => true, :message => '', :data => service_delivery_units_array} render json: @response end |
#unassigned_services ⇒ Object
65 66 67 68 69 70 71 |
# File 'app/controllers/logistics/core/service_delivery_units_controller.rb', line 65 def unassigned_services sdu = ServiceDeliveryUnit.find(params[:id]) ids = sdu.chargeable_services.map(&:id) unassigned_services = ChargeableService.where.not(id: ids) response = Mks::Common::MethodResponse.new(true, nil, unassigned_services, nil, nil) render json: response end |
#update ⇒ Object
PATCH/PUT /service_delivery_units/1 PATCH/PUT /service_delivery_units/1.json
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/logistics/core/service_delivery_units_controller.rb', line 35 def update if @service_delivery_unit.update_attributes(model_params) @service_delivery_unit.save @response = {:success => true, :message => 'Service delivery unit updated successfully!', :data => @service_delivery_unit} render json: @response else errors = Mks::Common::Util.(@service_delivery_unit, 'Service delivery unit') response = Mks::Common::MethodResponse.new(false,nil,nil,errors,nil) render json: response end end |