module Logistics module Core class DocumentTypesController < ApplicationController before_action :set_document_type, only: [:update] # GET /document_types # GET /document_types.json def index document_types = DocumentType.includes(:document_type_category, :document_type_origin) data = ApplicationRecord.as_json(document_types) response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end def lookup document_types = DocumentType.all.to_lookup response = Mks::Common::MethodResponse.new(true, nil, document_types, nil, nil) render json: response end # POST /document_types # POST /document_types.json def create @document_type = DocumentType.new(document_type_params) if @document_type.save response = Mks::Common::MethodResponse.new(true, "Document Type information saved successfully!", @document_type, nil, nil) else errors = Mks::Common::Util.error_messages @document_type, "Document Type" response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end # PATCH/PUT /document_types/1 # PATCH/PUT /document_types/1.json def update @document_type = DocumentType.find(params[:id]) if @document_type.update(document_type_params) response = Mks::Common::MethodResponse.new(true, "Document Type information updated successfully!", @document_type, nil, nil) else errors = Mks::Common::Util.error_messages @document_type, "Document Type" response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end private def set_document_type @document_type = DocumentType.find(params[:id]) end def document_type_params params.require(:document_type).permit(:code, :name, :description, :document_type_category_id, :document_type_origin_id) end end end end