mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-18 07:52:23 +01:00
fix bug: product amount cannot update
This commit is contained in:
parent
851294e8d9
commit
ec62931a78
@ -15,13 +15,7 @@ class API::ProductsController < API::ApiController
|
||||
def create
|
||||
authorize Product
|
||||
@product = Product.new(product_params)
|
||||
if @product.amount.present?
|
||||
if @product.amount.zero?
|
||||
@product.amount = nil
|
||||
else
|
||||
@product.amount *= 100
|
||||
end
|
||||
end
|
||||
@product.amount = ProductService.amount_multiplied_by_hundred(@product.amount)
|
||||
if @product.save
|
||||
render status: :created
|
||||
else
|
||||
@ -33,13 +27,7 @@ class API::ProductsController < API::ApiController
|
||||
authorize @product
|
||||
|
||||
product_parameters = product_params
|
||||
if product_parameters[:amount].present?
|
||||
if product_parameters[:amount].zero?
|
||||
product_parameters[:amount] = nil
|
||||
else
|
||||
product_parameters[:amount] *= 100
|
||||
end
|
||||
end
|
||||
product_parameters[:amount] = ProductService.amount_multiplied_by_hundred(product_parameters[:amount])
|
||||
if @product.update(product_parameters)
|
||||
render status: :ok
|
||||
else
|
||||
|
@ -5,4 +5,16 @@ class ProductService
|
||||
def self.list
|
||||
Product.all
|
||||
end
|
||||
|
||||
# amount params multiplied by hundred
|
||||
def self.amount_multiplied_by_hundred(amount)
|
||||
if amount.present?
|
||||
v = amount.to_f
|
||||
|
||||
return nil if v.zero?
|
||||
|
||||
return v * 100
|
||||
end
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user