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