← back to Hotelwallcoverings
/api/facets: count from filtered list (q/aesthetic/vendor), not raw catalog
d292928e537693d1bdf9178b2bca4ac8ee8cd5b0 · 2026-05-25 21:16:06 -0700 · Steve Abrams
Files touched
Diff
commit d292928e537693d1bdf9178b2bca4ac8ee8cd5b0
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Mon May 25 21:16:06 2026 -0700
/api/facets: count from filtered list (q/aesthetic/vendor), not raw catalog
---
server.js | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/server.js b/server.js
index c3bfb00..591d892 100644
--- a/server.js
+++ b/server.js
@@ -188,12 +188,23 @@ app.get('/api/sliders', (req, res) => {
});
app.get('/api/facets', (req, res) => {
+ // Apply the same q/aesthetic/vendor filters that /api/products uses so
+ // facet counts + `total` reflect the user's current selection, not the
+ // raw catalog. Pattern: build the filtered list once, then bucket.
+ const { q, aesthetic, vendor } = req.query;
+ let list = PRODUCTS_NICHE;
+ if (q) {
+ const needle = String(q).toLowerCase();
+ list = list.filter(p => (p.title || '').toLowerCase().includes(needle) || (p.tags || []).some(t => t.toLowerCase().includes(needle)));
+ }
+ if (aesthetic && aesthetic !== 'all') list = list.filter(p => p.aesthetic === aesthetic);
+ if (vendor && vendor !== 'all') list = list.filter(p => p.vendor === vendor);
const aesthetics = {}; const vendors = {};
- for (const p of PRODUCTS_NICHE) {
+ for (const p of list) {
aesthetics[p.aesthetic] = (aesthetics[p.aesthetic] || 0) + 1;
vendors[p.vendor] = (vendors[p.vendor] || 0) + 1;
}
- res.json({ aesthetics, vendors, total: PRODUCTS_NICHE.length });
+ res.json({ aesthetics, vendors, total: list.length });
});
app.get('/api/health', (req, res) => res.json({ status: 'ok', count: PRODUCTS_NICHE.length, dropped: DROPPED }));
← 998d748 404-guard: block .bak / .pre-* requests at HTTP surface (def
·
back to Hotelwallcoverings
·
add clean-URL routes for /care /history /sourcing /trade /vo b0ef967 →