Add All Systems List

This commit is contained in:
Luke Berndt
2023-06-17 09:32:26 -04:00
parent a6d8378b5b
commit 72798e4494
6 changed files with 104 additions and 26 deletions

View File

@@ -3,6 +3,7 @@ const System = require("../models/system");
const SystemStat = require("../models/system_stat");
const Talkgroup = require("../models/talkgroup");
const Group = require("../models/group");
const User = require("../models/user");
const crypto = require("crypto");
exports.isLoggedIn = function (req, res, next) {
@@ -12,6 +13,27 @@ exports.isLoggedIn = function (req, res, next) {
// -------------------------------------------
exports.listUserSystems = async function (req,res,next) {
if (!req.user.admin) {
res.status(401);
res.json({ success: false, message: "Not Authorized" });
return;
}
const users = await User.find({}, "_id email firstName lastName lastLogin");
let list = [];
console.log(users);
for (let index = 0; index < users.length; index++) {
let user = users[index].toObject();
const userId = new mongoose.Types.ObjectId(user._id);
const systems = await System.find({ userId: userId }, "name shortName description systemType city state county country lastActive");
user["systems"] = systems;
list.push(user);
}
res.json(list);
return;
}
exports.listAllSystems = async function (req, res, next) {
if (!req.user.admin) {
res.status(401);