← back to Pastelwallpaper
/api/facets: total counts the filtered list, not the entire niche slice
d896cb42bab5e40dc71b6d751415e4b619329ce0 · 2026-05-25 21:24:58 -0700 · Steve
Endpoint now accepts the same ?q / ?aesthetic / ?vendor params as
/api/products and computes the aesthetics map, vendors map, and total
off the filtered list. Previously total always reported the full
PRODUCTS_NICHE length, which made the result-count badge wrong as soon
as the user typed in the search box or picked an aesthetic chip.
Files touched
Diff
commit d896cb42bab5e40dc71b6d751415e4b619329ce0
Author: Steve <steve@designerwallcoverings.com>
Date: Mon May 25 21:24:58 2026 -0700
/api/facets: total counts the filtered list, not the entire niche slice
Endpoint now accepts the same ?q / ?aesthetic / ?vendor params as
/api/products and computes the aesthetics map, vendors map, and total
off the filtered list. Previously total always reported the full
PRODUCTS_NICHE length, which made the result-count badge wrong as soon
as the user typed in the search box or picked an aesthetic chip.
---
server.js | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/server.js b/server.js
index 76baf0c..cf08f9d 100644
--- a/server.js
+++ b/server.js
@@ -203,12 +203,20 @@ app.get('/api/sliders', (req, res) => {
});
app.get('/api/facets', (req, res) => {
+ 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 }));
← 1301d44 wire api-vendor-redact middleware + scrub p.vendor render
·
back to Pastelwallpaper
·
site.config rails: align with actual catalog buckets fd2ae5f →