1
0
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:
Du Peng 2022-08-04 14:02:19 +02:00 committed by Sylvain
parent 851294e8d9
commit ec62931a78
2 changed files with 14 additions and 14 deletions

View File

@ -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

View File

@ -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