← back to Greenwallcoverings
fix: /api/facets total counts filtered list (q/aesthetic/vendor)
6a267e10868ec1ea94879dc666ea9088d9f5f7bf · 2026-05-25 21:05:57 -0700 · Steve
Files touched
Diff
commit 6a267e10868ec1ea94879dc666ea9088d9f5f7bf
Author: Steve <steve@designerwallcoverings.com>
Date: Mon May 25 21:05:57 2026 -0700
fix: /api/facets total counts filtered list (q/aesthetic/vendor)
---
server.js | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/server.js b/server.js
index 6cc1a81..5eed479 100644
--- a/server.js
+++ b/server.js
@@ -185,12 +185,22 @@ app.get('/api/sliders', (req, res) => {
});
app.get('/api/facets', (req, res) => {
+ // `total` must count the FILTERED list (q/aesthetic/vendor) so the stat-line
+ // in the UI reflects the visible product count, not the global catalog.
+ 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 => String(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 }));
← cfa850d retag aesthetic from PG: 581 rows updated
·
back to Greenwallcoverings
·
wire api-vendor-redact middleware: strip vendor field + vend 50784ee →