Class: Logistics::Core::OperationsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Logistics::Core::OperationsController
- Defined in:
- app/controllers/logistics/core/operations_controller.rb
Instance Method Summary collapse
- #assign ⇒ Object
- #assigned ⇒ Object
- #create ⇒ Object
- #filter_fresh_by_client ⇒ Object
- #fresh ⇒ Object
- #index ⇒ Object
- #unassigned ⇒ Object
- #update ⇒ Object
Instance Method Details
#assign ⇒ Object
75 76 77 78 |
# File 'app/controllers/logistics/core/operations_controller.rb', line 75 def assign response = @service.assign_owner(assign_params[:payload]) render json: response end |
#assigned ⇒ Object
61 62 63 64 65 66 |
# File 'app/controllers/logistics/core/operations_controller.rb', line 61 def assigned operations = Operation.where.not(owner_id: nil) data = ApplicationRecord.as_json(operations) response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end |
#create ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/logistics/core/operations_controller.rb', line 24 def create service = OperationService.new result, @operation = service.save(model_params) if result response = Mks::Common::MethodResponse.new(true, 'Operation saved successfully!', @operation, nil, nil) else errors = Mks::Common::Util. @operation, 'Operation' response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end |
#filter_fresh_by_client ⇒ Object
54 55 56 57 58 59 |
# File 'app/controllers/logistics/core/operations_controller.rb', line 54 def filter_fresh_by_client operations = Operation.joins(:offer_request).fresh.where('logistics_core_offer_requests.client_id = ?', params[:id]) data = ApplicationRecord.as_json(operations) response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end |
#fresh ⇒ Object
47 48 49 50 51 52 |
# File 'app/controllers/logistics/core/operations_controller.rb', line 47 def fresh operations = Operation.fresh data = ApplicationRecord.as_json(operations) response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end |
#index ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/logistics/core/operations_controller.rb', line 7 def index if params.key?('simple') operations = Operation.includes(:owner, {offer_request: :client}).order('id DESC') data = Logistics::Core::ApplicationRecord.as_json(operations, SimpleOperationSerializer) else operations = Operation.includes(:declarant, :declaration_type, :transport_mode, :customs_office, :customs_office_unit, :country_of_origin, :acquisition_mode, :payment_term, :delivery_term, :container_arrangement, :customs_transport_tariff, :esl_transport_tariff, :warehouse, :owner, :offer_request).order('id DESC') data = Logistics::Core::ApplicationRecord.as_json(operations) end response = {success: true, data: data} render json: response end |
#unassigned ⇒ Object
68 69 70 71 72 73 |
# File 'app/controllers/logistics/core/operations_controller.rb', line 68 def unassigned operations = Operation.where(owner_id: nil) data = ApplicationRecord.as_json(operations) response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end |
#update ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/logistics/core/operations_controller.rb', line 36 def update operation = Operation.find(params[:id]) update_attributes(operation, model_params) if operation.save response = Mks::Common::MethodResponse.new(true, 'Operation updated successfully!', nil, nil, nil) else response = Mks::Common::MethodResponse.new(false, nil, nil, ['Operation update failed!'], nil) end render json: response end |