From f847bfc920f0dfaa1ce59d4c7fbf83f778eb1971 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 8 Aug 2024 22:24:58 -0700 Subject: [PATCH] Fixed an evaluation error in getMonitorsByUserId and fixed a logical error in getMonitorById --- Server/db/mongo/modules/monitorModule.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index 15f431673..f3579f369 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -81,14 +81,16 @@ const getMonitorById = async (req, res) => { // If more than numToDisplay checks, pick every nth check if (numToDisplay !== undefined && checks && checks.length > numToDisplay) { const n = Math.ceil(checks.length / numToDisplay); - checks = checks.filter((_, index) => index % n === 0); + checks = checks.filter( + (_, index) => index % n === 0 || index === checks.length - 1 + ); } // Normalize checks if requested - if (normalize) { - checks = NormalizeData(checks, 10, 100); + if (normalize !== undefined) { + checks = NormalizeData(checks, 1, 100); } - + console.log(checks.length); const notifications = await Notification.find({ monitorId: monitor._id }); const monitorWithChecks = { ...monitor.toObject(), checks, notifications }; return monitorWithChecks; @@ -148,7 +150,7 @@ const getMonitorsByUserId = async (req, res) => { .limit(limit); //Normalize checks if requested - if (normalize === true) { + if (normalize !== undefined) { checks = NormalizeData(checks, 10, 100); }