Sha256: bbedc71530b40ba3ed16270162c216bc559745a7982f62915ca9de65c6b8142d

Contents?: true

Size: 1.45 KB

Versions: 11

Compression:

Stored size: 1.45 KB

Contents

module Comee
  module Core
    class ProductsController < ApplicationController
      include Common

      def index
        super do
          products = Product.leafs
          products.then(&paginate)
        end
      end

      def show
        super do
          product = Comee::Core::Product.with_attached_images.find(params[:id])
          product
        end
      end

      def master_prices
        data = MasterPrice.includes(:product_lookup, :supplier, :product)
                          .where(product_id: price_params[:product_ids])
        render json: {success: true, data: serialize(data)}
      end

      def client_prices
        data = ClientPrice.where(product_id: price_params[:product_ids])
        render json: {success: true, data: serialize(data)}
      end

      def categories
        root = Product.find_by(code: "root")
        render json: {success: true, data: serialize(root.children)}
      end

      def filter
        products = Product.ransack(params[:q]).result
        render json: {success: true, data: serialize(products)}
      end

      private

      def model_params
        params.required(:payload).permit(:code, :name, :description, :parent_id, :thumbnail_image, :preferred_units, :source_id, :weight,
                                         :weight_unit_id, :dimensions, :hs_code, :hs_description, images: [])
      end

      def price_params
        params.require(:payload).permit(product_ids: [])
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
comee_core-0.1.96 app/controllers/comee/core/products_controller.rb
comee_core-0.1.95 app/controllers/comee/core/products_controller.rb
comee_core-0.1.94 app/controllers/comee/core/products_controller.rb
comee_core-0.1.93 app/controllers/comee/core/products_controller.rb
comee_core-0.1.92 app/controllers/comee/core/products_controller.rb
comee_core-0.1.91 app/controllers/comee/core/products_controller.rb
comee_core-0.1.90 app/controllers/comee/core/products_controller.rb
comee_core-0.1.89 app/controllers/comee/core/products_controller.rb
comee_core-0.1.88 app/controllers/comee/core/products_controller.rb
comee_core-0.1.87 app/controllers/comee/core/products_controller.rb
comee_core-0.1.86 app/controllers/comee/core/products_controller.rb