Sha256: 74a57845fec2f1ba3f65f78e8037701a417015f4a430fc2cd79cc51ba87d0896

Contents?: true

Size: 1.68 KB

Versions: 9

Compression:

Stored size: 1.68 KB

Contents

module Logistics
	module Core
	  class RequiredDocumentsController < ApplicationController
	  	before_action :set_required_document, only: [:update]

      def index
        required_documents = RequiredDocument.where(agency_permit_document_id: params[:id])
        data = ApplicationRecord.as_json(required_documents)
        response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil)
        render json: response
      end

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

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

      private

      def set_required_document
        @required_document = RequiredDocument.find(params[:id])
      end

      def required_document_params
        params.require(:required_document).permit(:document_type_id, :agency_permit_document_id, :original, :copy, :certified, :is_mandatory, :is_endorsed)
      end
	  end
	end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
logistics_core-21.11.2 app/controllers/logistics/core/required_documents_controller.rb
logistics_core-21.11.1 app/controllers/logistics/core/required_documents_controller.rb
logistics_core-21.08.1 app/controllers/logistics/core/required_documents_controller.rb
logistics_core-21.03.1 app/controllers/logistics/core/required_documents_controller.rb
logistics_core-20.10.3 app/controllers/logistics/core/required_documents_controller.rb
logistics_core-20.10.2 app/controllers/logistics/core/required_documents_controller.rb
logistics_core-20.10.1 app/controllers/logistics/core/required_documents_controller.rb
logistics_core-20.9.1 app/controllers/logistics/core/required_documents_controller.rb
logistics_core-20.8.1 app/controllers/logistics/core/required_documents_controller.rb