From 44f52fd7e47d99ac2a249bcbf8af5074d21a86fd Mon Sep 17 00:00:00 2001 From: gadgethd <111318106+gadgethd@users.noreply.github.com> Date: Sat, 15 Aug 2026 22:52:47 +0000 Subject: [PATCH] fix(api): coerce COUNT(*) string to numeric adverts_in_window --- backend/src/api/routes/nodes.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/src/api/routes/nodes.ts b/backend/src/api/routes/nodes.ts index 30f56cf..2099564 100644 --- a/backend/src/api/routes/nodes.ts +++ b/backend/src/api/routes/nodes.ts @@ -208,9 +208,15 @@ export function registerNodeRoutes(router: Router, deps: NodesRouteDeps): void { return; } const rows = await getTopAdvertingRepeaters(hours, limit, network); - topAdvertsCache.set(cacheKey, { ts: Date.now(), data: rows }); + // COUNT(*) arrives as a string from node-postgres; coerce to number so + // the public contract exposes a numeric adverts_in_window. + const normalized = (rows as Array>).map((row) => ({ + ...row, + adverts_in_window: Number(row.adverts_in_window ?? 0), + })); + topAdvertsCache.set(cacheKey, { ts: Date.now(), data: normalized }); res.setHeader('Cache-Control', 'public, max-age=3600, stale-while-revalidate=600'); - res.json(rows); + res.json(normalized); } catch (err) { console.error('[api] GET /nodes/top-adverts', (err as Error).message); res.status(500).json({ error: 'Internal server error' });