Class: Comee::Core::CustomerOrderItemsController

Inherits:
ApplicationController show all
Includes:
Common
Defined in:
app/controllers/comee/core/customer_order_items_controller.rb

Instance Method Summary collapse

Methods included from Common

#create, #show, #update

Methods included from Pagination

#default_per_page, #order_by, #order_direction, #page_no, #paginate, #paginate_offset, #per_page

Methods inherited from ApplicationController

#application_code, #authenticate, #current_application, #current_user, #render_content, #render_error, #skip_bullet

Instance Method Details

#cancelObject



15
16
17
18
# File 'app/controllers/comee/core/customer_order_items_controller.rb', line 15

def cancel
  CustomerOrderItem.where(id: params[:ids]).update_all(canceled: true)
  render json: {success: true}
end

#destroyObject



27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/comee/core/customer_order_items_controller.rb', line 27

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

#filterObject



20
21
22
23
24
25
# File 'app/controllers/comee/core/customer_order_items_controller.rb', line 20

def filter
  data = CustomerOrderItem.includes(:product, :unit)
                          .ransack(params[:q])
                          .result
  render_content(data, {include: ["unit"]})
end

#indexObject



6
7
8
9
10
11
12
13
# File 'app/controllers/comee/core/customer_order_items_controller.rb', line 6

def index
  super do
    [
      CustomerOrderItem.includes(:product, :unit).all,
      include: ["unit"]
    ]
  end
end