Sha256: d08503f4cd48795cf431ee7c3ab7172e9dfd272c424379f2843628acd878fe12

Contents?: true

Size: 1.32 KB

Versions: 43

Compression:

Stored size: 1.32 KB

Contents

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

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
comee_core-0.2.14 app/controllers/comee/core/customer_order_items_controller.rb
comee_core-0.2.13 app/controllers/comee/core/customer_order_items_controller.rb
comee_core-0.2.12 app/controllers/comee/core/customer_order_items_controller.rb