Class: Logistics::Core::CommonDocumentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/logistics/core/common_documents_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/logistics/core/common_documents_controller.rb', line 21

def create
  @common_document = CommonDocument.new(common_document_params)
  if @common_document.save
    response = Mks::Common::MethodResponse.new(true, 'Common document saved successfully!', @common_document, nil, nil)
  else
    errors = Mks::Common::Util.error_messages @common_document, 'Common document'
    response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil)
  end
  render json: response
end

#filter_by_operationObject



13
14
15
16
17
18
19
# File 'app/controllers/logistics/core/common_documents_controller.rb', line 13

def filter_by_operation
  common_documents = CommonDocument.includes(:document_type)
                                   .where(:operation_id => params[:id])
  data = ApplicationRecord.as_json(common_documents)
  response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil)
  render json: response
end

#indexObject



6
7
8
9
10
11
# File 'app/controllers/logistics/core/common_documents_controller.rb', line 6

def index
  common_documents = CommonDocument.includes(:document_type)
  data = ApplicationRecord.as_json(common_documents)
  response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil)
  render json: response
end

#updateObject



32
33
34
35
36
37
38
39
40
# File 'app/controllers/logistics/core/common_documents_controller.rb', line 32

def update
  if @common_document.update(common_document_params)
    response = Mks::Common::MethodResponse.new(true, "Common document updated successfully!", @common_document, nil, nil)
  else
    errors = Mks::Common::Util.error_messages @common_document, "Common document"
    response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil)
  end
  render json: response
end