Class: Logistics::Core::OperationService

Inherits:
BaseService show all
Defined in:
app/services/logistics/core/operation_service.rb

Instance Method Summary collapse

Methods inherited from BaseService

#to_json

Instance Method Details

#assign_owner(params) ⇒ Object

This method takes a list of owner_id / op_ids pairs and does the assignment @param:

params -> [{owner_id: 1, op_ids: [2, 3, 4]}, {owner_id: 2, op_ids: [5, 6]}]


26
27
28
29
30
31
32
33
34
35
36
# File 'app/services/logistics/core/operation_service.rb', line 26

def assign_owner(params)
  op_ids = params.map { |param| param[:op_ids] }.flatten
  operations = Operation.where(id: op_ids)
  updated_list = update_owner_data(operations, params)
  Operation.transaction do
    updated_list.each(&:save!)
  end
  Mks::Common::MethodResponse.new(true, 'Owners Assigned!', nil, nil, nil)
rescue ActiveRecord::RecordInvalid => exception
  Mks::Common::MethodResponse.new(false, nil, nil, [exception.message], nil)
end

#save(params) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/services/logistics/core/operation_service.rb', line 6

def save(params)
  operation = Operation.new(params)
  result = operation.save
  if result
    OperationSummary.create(:operation => operation)
    documents = get_additional_documents(params)
    common_docs = CommonDocument.all
    converted = convert_documents(operation, documents)
    common_converted = convert_documents(operation, common_docs)
    OperationDocument.create(common_converted)
    OperationDocument.create!(converted)
  end
  [result, operation]
end