mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-03-21 12:29:03 +01:00
(bug) product store filtering
- Do not reset the category when reseting the filters - Prevent filtering by internal stock when user is not privileged
This commit is contained in:
parent
46d1127efc
commit
bc09450418
@ -9,7 +9,7 @@ class API::ProductsController < API::ApiController
|
||||
MOVEMENTS_PER_PAGE = 10
|
||||
|
||||
def index
|
||||
@products = ProductService.list(params)
|
||||
@products = ProductService.list(params, current_user)
|
||||
end
|
||||
|
||||
def show
|
||||
|
@ -89,8 +89,8 @@ const Store: React.FC<StoreProps> = ({ onError, onSuccess, currentUser, uiRouter
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchProducts().then(scrollToProducts);
|
||||
if (resources.filters.ready) {
|
||||
fetchProducts().then(scrollToProducts);
|
||||
uiRouter.stateService.transitionTo(uiRouter.globals.current, ProductLib.indexFiltersToRouterParams(resources.filters.data));
|
||||
}
|
||||
}, [resources.filters]);
|
||||
@ -188,7 +188,10 @@ const Store: React.FC<StoreProps> = ({ onError, onSuccess, currentUser, uiRouter
|
||||
...draft,
|
||||
filters: {
|
||||
...draft.filters,
|
||||
data: initFilters
|
||||
data: {
|
||||
...initFilters,
|
||||
categories: draft.filters.data.categories
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -5,13 +5,13 @@ class ProductService
|
||||
class << self
|
||||
PRODUCTS_PER_PAGE = 12
|
||||
|
||||
def list(filters)
|
||||
def list(filters, operator)
|
||||
products = Product.includes(:product_images)
|
||||
products = filter_by_active(products, filters)
|
||||
products = filter_by_categories(products, filters)
|
||||
products = filter_by_machines(products, filters)
|
||||
products = filter_by_keyword_or_reference(products, filters)
|
||||
products = filter_by_stock(products, filters)
|
||||
products = filter_by_stock(products, filters, operator)
|
||||
products = products_ordering(products, filters)
|
||||
|
||||
total_count = products.count
|
||||
@ -110,7 +110,9 @@ class ProductService
|
||||
{ sku: filters[:keywords], query: "%#{filters[:keywords]}%" })
|
||||
end
|
||||
|
||||
def filter_by_stock(products, filters)
|
||||
def filter_by_stock(products, filters, operator)
|
||||
filters[:stock_type] = 'external' unless operator.privileged?
|
||||
|
||||
products.where("(stock ->> '#{filters[:stock_type]}')::int >= #{filters[:stock_from]}") if filters[:stock_from].to_i.positive?
|
||||
products.where("(stock ->> '#{filters[:stock_type]}')::int <= #{filters[:stock_to]}") if filters[:stock_to].to_i.positive?
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user