diff --git a/src/index.js b/src/index.js index c9d057c..eec49b3 100644 --- a/src/index.js +++ b/src/index.js @@ -161,6 +161,41 @@ app.get('/api/v1/nodes/:nodeId/mqtt-metrics', async (req, res) => { } }); +app.get('/api/v1/nodes/:nodeId/traceroutes', async (req, res) => { + try { + + const nodeId = parseInt(req.params.nodeId); + const count = req.query.count ? parseInt(req.query.count) : 10; // can't set to null because of $queryRaw + + // find node + const node = await prisma.node.findFirst({ + where: { + node_id: nodeId, + }, + }); + + // make sure node exists + if(!node){ + res.status(404).json({ + message: "Not Found", + }); + } + + // get latest traceroutes + const traceroutes = await prisma.$queryRaw`SELECT * FROM traceroutes WHERE node_id = ${node.node_id} and JSON_LENGTH(route) > 0 and gateway_id is not null order by id desc limit ${count}`; + + res.json({ + traceroutes: traceroutes, + }); + + } catch(err) { + console.error(err); + res.status(500).json({ + message: "Something went wrong, try again later.", + }); + } +}); + app.get('/api/v1/stats/hardware-models', async (req, res) => { try { diff --git a/src/public/index.html b/src/public/index.html index e39d3a8..d0d9686 100644 --- a/src/public/index.html +++ b/src/public/index.html @@ -493,7 +493,7 @@
{{ traceroute.route.length }} hops {{ traceroute.channel_id ? `on ${traceroute.channel_id}` : '' }}
+