module Comee module Core class CustomerOrderItemsController < ApplicationController include Common def index super do [ CustomerOrderItem.includes(:product, :unit).all, fields: ["unit"] ] end end def cancel CustomerOrderItem.where(id: params[:ids]).update_all(canceled: true) render json: {success: true} end def filter data = CustomerOrderItem.includes(:product, :unit).ransack(params[:q]).result render_content(data, {fields: ["unit"]}) end def destroy item = CustomerOrderItem.find(params[:id]) if item.customer_order.draft? item.destroy render json: {success: true} else render json: {success: false, error: "Customer order should be in draft state."}, status: :forbidden end end private def model_params params.require(:payload) .permit( :customer_item_no, :customer_item_description, :quantity, :price, :total_price, :delivery_date, :canceled, :product_id, :customer_order_id, :unit_id ) end end end end