Merge branch 'master' into feature/contact

This commit is contained in:
Luke Berndt
2023-07-09 10:34:00 -04:00
committed by GitHub
7 changed files with 118 additions and 13 deletions

View File

@@ -13,7 +13,44 @@ exports.isLoggedIn = function (req, res, next) {
// -------------------------------------------
exports.listUserSystems = async function (req, res, next) {
exports.listActiveUsers = async function (req,res,next) {
if (!req.user.admin) {
res.status(401);
res.json({ success: false, message: "Not Authorized" });
return;
}
let users = {};
let fromDate = new Date(Date.now() - 60 * 60 * 24 * 30 * 1000);
const systems = await System.find({lastActive: {$gte: fromDate}}).populate('userId', "screenName").catch( err => {
console.error("Error - get_systems: " + err.message);
res.json({
success: false,
message: err
});
return;
});
for (let index = 0; index < systems.length; index++) {
const system = systems[index];
if (!users.hasOwnProperty(system.userId.toString())) {
const user = await User.findById(system.userId, "_id email firstName lastName lastLogin");
users[system.userId.toString()] = user.email;
}
}
let list = [];
for (const id in users) {
list.push(users[id]);
}
res.json(list);
return;
}
exports.listUserSystems = async function (req,res,next) {
if (!req.user.admin) {
res.status(401);
res.json({ success: false, message: "Not Authorized" });

View File

@@ -153,6 +153,7 @@ app.get("/groups/:shortName/:groupId?", isLoggedIn, groups.getGroups);
app.delete("/groups/:shortName/:groupId", isLoggedIn, groups.deleteGroup);
app.get("/systems", isLoggedIn, systems.listSystems)
app.get("/admin/systems", isAdmin, systems.listAllSystems)
app.get("/admin/users/active", isAdmin, systems.listActiveUsers)
app.get("/admin/users", isAdmin, systems.listUserSystems)
app.delete("/systems/:shortName", isLoggedIn, systems.deleteSystem)
app.post("/systems/:shortName", [isLoggedIn, systems.ownSystem, systems.validateSystem, systems.updateSystem])