From 0c9a75a2ab9ea564918a1e31fa2caf2ac07a6360 Mon Sep 17 00:00:00 2001 From: Vova Stelmashchuk Date: Sun, 1 Sep 2024 13:25:52 +0000 Subject: [PATCH] update filters --- database/filetrs.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/database/filetrs.js b/database/filetrs.js index 7574249..aa734ad 100644 --- a/database/filetrs.js +++ b/database/filetrs.js @@ -125,6 +125,9 @@ async function buildFutureCounter(inputFilters, filterKey, collectionName) { const futureFilter = { ...filters, [filterKey]: theFilterValue }; + const futureSelectedFilterCount = Object.keys(futureFilter).reduce((acc, key) => acc + futureFilter[key].length, 0); + const isAddToIndex = futureSelectedFilterCount < 3; + const count = await getCocktailCountByFilter(futureFilter); return { @@ -132,6 +135,7 @@ async function buildFutureCounter(inputFilters, filterKey, collectionName) { query: filterToPath(futureFilter), count: count, isActive: isInclude, + isAddToIndex: isAddToIndex, }; })); @@ -154,6 +158,9 @@ async function getCocktailFilterState(filters, skip, limit, sortType) { buildFutureCounter(filters, 'tags', 'tags') ]); + const selectedFilterCount = Object.keys(filters).reduce((acc, key) => acc + filters[key].length, 0); + const isAddToIndex = selectedFilterCount < 3; + return { totalCount, cocktails, @@ -164,7 +171,8 @@ async function getCocktailFilterState(filters, skip, limit, sortType) { 3: toolsFuture, 4: goodsFuture, 5: tagsFuture, - } + }, + isAddToIndex: isAddToIndex, } }