Sha256: 77ec62a3d7472303093f0cd26da5b50f5284532a60af5f77d3f82cf1c8212765

Contents?: true

Size: 1.87 KB

Versions: 218

Compression:

Stored size: 1.87 KB

Contents

require_dependency "ishapi/application_controller"

module Ishapi
  class OrderItemsController < ApplicationController
    before_action :check_profile, :only => [ :create ]

    def create
      authorize! :add, CoTailors::OrderItem
      @order_item = CoTailors::OrderItem.new params['order_item'].permit( :quantity, :kind, :fabric )
      @order_item.order_id = @current_order.id
      @order_item.measurement = @measurement
      @order_item.cost = case params[:order_item][:kind]
                         when CoTailors::OrderItem::KIND_SHIRT
                           CoTailors::Product.where( :kind => 'shirt' ).first.cost
                         when CoTailors::OrderItem::KIND_PANTS
                           CoTailors::Product.where( :kind => 'pants' ).first.cost
                         when CoTailors::OrderItem::KIND_SUIT
                           CoTailors::Product.where( :kind => 'suit' ).first.cost
                         end
      @order_item.measurement = CoTailors::ProfileMeasurement.create params['order_item'].permit( CoTailors::Order::MEASUREMENT_PARAMS )

      # byebug

      if params[:order_item][:saveMeasurement]
        m = @current_profile.measurement || CoTailors::ProfileMeasurement.create( :profile => @current_profile )
        flag = m.update_attributes( measurement_params )
        if !flag
          render :json => { :statuc => :not_ok, :error => m.errors.messages }
          return 
        end
      end
      
      flag = @order_item.save
      if flag
        render :json => { :status => :ok, :message => 'Successfully put an order item' }
      else
        render :json => { :status => :not_ok, :error => @order_item.errors.messages }
      end
    end

    #
    # private
    #
    private

    def measurement_params
      out = {}
      out[:neck_around] = params[:order_item][:neckAround] if params[:order_item][:neckAround]
      out
    end

  end
end

Version data entries

218 entries across 218 versions & 1 rubygems

Version Path
ishapi-0.1.8.316 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.315 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.314 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.313 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.312 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.310 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.309 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.308 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.307 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.306 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.305 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.304 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.303 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.302 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.301 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.300 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.298 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.297 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.296 app/controllers/ishapi/order_items_controller.rb
ishapi-0.1.8.295 app/controllers/ishapi/order_items_controller.rb