begin implementing aggregate query

This commit is contained in:
Alex Holliday
2024-12-31 15:05:14 -08:00
parent cf3305611f
commit 247bf44406

View File

@@ -373,6 +373,30 @@ const getMonitorStatsById = async (req) => {
}
};
const getHardwareDetailsById = async (req) => {
try {
const { monitorId } = req.params;
const monitor = await Monitor.findById(monitorId);
const hardwareStats = await HardwareCheck.aggregate([
{
$match: {
monitorId: monitor._id,
},
},
{
$facet: [],
},
]);
return hardwareStats;
} catch (error) {
error.service = SERVICE_NAME;
error.method = "getHardwareDetailsById";
throw error;
}
};
/**
* Get a monitor by ID
* @async
@@ -660,6 +684,7 @@ export {
deleteMonitorsByUserId,
editMonitor,
addDemoMonitors,
getHardwareDetailsById,
};
// Helper functions