[object Object]

← back to Watches

fix(app.js): /api/watches now returns paginated wrapper, not bare array

10ed798000515c3c9882ffae021fca698dbb59e2 · 2026-05-19 21:51:38 -0700 · Steve Abrams

loadWatches() was doing `allWatches = await response.json()` against
/api/watches, but server.js:442 returns `{total, page, limit, totalPages, watches: [...]}`
(default limit=50). So allWatches was getting the wrapper object, and every
subsequent .forEach/.filter on it was broken (silently — Array.prototype
methods don't exist on plain objects so the comparison list on index.html
was non-functional).

Defensive fix: extract .watches if the response is an object (handles old
bare-array API too), and request ?limit=9999 so we still get the whole
catalog now that the endpoint paginates.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Files touched

Diff

commit 10ed798000515c3c9882ffae021fca698dbb59e2
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Tue May 19 21:51:38 2026 -0700

    fix(app.js): /api/watches now returns paginated wrapper, not bare array
    
    loadWatches() was doing `allWatches = await response.json()` against
    /api/watches, but server.js:442 returns `{total, page, limit, totalPages, watches: [...]}`
    (default limit=50). So allWatches was getting the wrapper object, and every
    subsequent .forEach/.filter on it was broken (silently — Array.prototype
    methods don't exist on plain objects so the comparison list on index.html
    was non-functional).
    
    Defensive fix: extract .watches if the response is an object (handles old
    bare-array API too), and request ?limit=9999 so we still get the whole
    catalog now that the endpoint paginates.
    
    Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---
 public/app.js | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/public/app.js b/public/app.js
index 31d1289..f7b7b41 100755
--- a/public/app.js
+++ b/public/app.js
@@ -88,8 +88,9 @@ async function loadStatistics() {
 // Load watches
 async function loadWatches() {
     try {
-        const response = await fetch('/api/watches');
-        allWatches = await response.json();
+        const response = await fetch('/api/watches?limit=9999');
+        const data = await response.json();
+        allWatches = Array.isArray(data) ? data : (data.watches || []);
         filteredWatches = [...allWatches];
 
         // Count total data points

← db8e98e Add snapshot-file 404 guard for .bak/.pre-/.orig/.rej paths  ·  back to Watches  ·  security: strip hardcoded dw_admin DSN password -> env-first 9177627 →