diff --git a/backend/controllers/systems.js b/backend/controllers/systems.js index ba07913..dc8611a 100644 --- a/backend/controllers/systems.js +++ b/backend/controllers/systems.js @@ -99,7 +99,8 @@ exports.contact_system = async function(req, res) { exports.get_systems = async function (req, res) { let fromDate = new Date(Date.now() - 60 * 60 * 24 * 30 * 1000); - const results = await System.find({lastActive: {$gte: fromDate}}).populate('userId', "screenName").catch( err => { + //const results = await System.find({lastActive: {$gte: fromDate}}).populate('userId', "screenName").catch( err => { + const results = await System.find({active: true}).populate('userId', "screenName").catch( err => { console.error("Error - get_systems: " + err.message); res.status(500); res.json({ diff --git a/backend/sys_stats.js b/backend/sys_stats.js index ad1cb27..f05b4cf 100644 --- a/backend/sys_stats.js +++ b/backend/sys_stats.js @@ -18,12 +18,17 @@ async function updateActiveSystems() { item.active = true; item.callAvg = callTotals[item.shortName][0] / timePeriod; item.lastActive = new Date(); - await item.save(); } else { item.active = false; item.callAvg = 0; - await item.save(); } + let fromDate = new Date(Date.now() - 60 * 60 * 24 * 30 * 1000); + if (item.lastActive < fromDate) { + item.active = false; + } else { + item.active = true; + } + await item.save(); }; }