module Logistics module Core class KilogramMinimumRatesController < ApplicationController before_action :set_kilogram_minimum_rate, only: [:update] def index kilogram_minimum_rates = KilogramMinimumRate.all data = ActiveModelSerializers::SerializableResource.new(kilogram_minimum_rates).as_json render json: data end def create kilogram_minimum_rate = KilogramMinimumRate.new(kilogram_minimum_rate_params) cs_uoc = ChargeableServiceUnitOfCharge.where(service_delivery_unit_id: params[:kilogram_minimum_rate][:service_delivery_unit_id], chargeable_service_id: params[:kilogram_minimum_rate][:chargeable_service_id]) kilogram_minimum_rate.chargeable_service_unit_of_charge_id = cs_uoc[0].id unless cs_uoc.empty? if kilogram_minimum_rate.valid? kilogram_minimum_rate.save res = Mks::Common::MethodResponse.new(true, 'Minimum rate set successfully !', nil, nil, nil) else errors = Mks::Common::Util.error_messages(kilogram_minimum_rate, 'Kilogram Minimum Rate') res = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: res end def update cs_uoc = ChargeableServiceUnitOfCharge.where(service_delivery_unit_id: params[:kilogram_minimum_rate][:service_delivery_unit_id], chargeable_service_id: params[:kilogram_minimum_rate][:chargeable_service_id]) @kilogram_minimum_rate.chargeable_service_unit_of_charge_id = cs_uoc[0].id unless cs_uoc.empty? if @kilogram_minimum_rate.update(kilogram_minimum_rate_params) res = Mks::Common::MethodResponse.new(true, 'Minimum rate updated successfully !', nil, nil) else errors = Mks::Common::Util.error_messages(@kilogram_minimum_rate, 'Kilogram Minimum Rate') res = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: res end private def kilogram_minimum_rate_params params.require('kilogram_minimum_rate').permit(:transaction_type_id, :minimum_price) end def set_kilogram_minimum_rate @kilogram_minimum_rate = KilogramMinimumRate.find(params[:id]) end end end end