implement sidebar to show popular meshtastic devices

This commit is contained in:
liamcottle
2024-03-13 21:02:58 +13:00
parent 07c1314cd8
commit 1e5cd0b3c8
2 changed files with 192 additions and 138 deletions

View File

@ -84,4 +84,40 @@ app.get('/api/v1/nodes', async (req, res) => {
}
});
app.get('/api/v1/stats/hardware-models', async (req, res) => {
try {
// get nodes from db
const results = await prisma.node.groupBy({
by: ['hardware_model'],
orderBy: {
_count: {
hardware_model: 'desc',
},
},
_count: {
hardware_model: true,
},
});
const hardwareModelStats = results.map((result) => {
return {
count: result._count.hardware_model,
hardware_model: result.hardware_model,
hardware_model_name: HardwareModel.valuesById[result.hardware_model] ?? "UNKNOWN",
};
});
res.json({
hardware_model_stats: hardwareModelStats,
});
} catch(err) {
console.error(err);
res.status(500).json({
message: "Something went wrong, try again later.",
});
}
});
app.listen(8080);