mirror of
https://github.com/gadgethd/ukmesh.git
synced 2026-10-23 06:12:27 +00:00
fix(api): coerce COUNT(*) string to numeric adverts_in_window
This commit is contained in:
1 parent
79e5e4ad0b
commit
44f52fd7e4
1 file changed
+8
-2
@@ -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<Record<string, unknown>>).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' });
|
||||
|
||||
Reference in new issue
Block a user