if no nodes return nothing for getDeviceDetails #6637

Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
si458 2025-01-03 16:59:29 +00:00
parent d1cb184e9e
commit e66776c5da

View File

@ -8049,42 +8049,46 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
parent.common.unEscapeAllLinksFieldName(docs); parent.common.unEscapeAllLinksFieldName(docs);
var results = [], resultPendingCount = 0; var results = [], resultPendingCount = 0;
for (i in docs) { if (docs.length == 0) { // no results return blank array
// Check device links, if a link points to an unknown user, remove it. func(docs, type);
parent.cleanDevice(docs[i]); } else {
for (i in docs) {
// Check device links, if a link points to an unknown user, remove it.
parent.cleanDevice(docs[i]);
// Fetch the node from the database // Fetch the node from the database
resultPendingCount++; resultPendingCount++;
const getNodeFunc = function (node, rights, visible) { const getNodeFunc = function (node, rights, visible) {
if ((node != null) && (visible == true)) { if ((node != null) && (visible == true)) {
const getNodeSysInfoFunc = function (err, docs) { const getNodeSysInfoFunc = function (err, docs) {
const getNodeNetInfoFunc = function (err, docs) { const getNodeNetInfoFunc = function (err, docs) {
var netinfo = null; var netinfo = null;
if ((err == null) && (docs != null) && (docs.length == 1)) { netinfo = docs[0]; } if ((err == null) && (docs != null) && (docs.length == 1)) { netinfo = docs[0]; }
resultPendingCount--; resultPendingCount--;
getNodeNetInfoFunc.results.push({ node: parent.CloneSafeNode(getNodeNetInfoFunc.node), sys: getNodeNetInfoFunc.sysinfo, net: netinfo }); getNodeNetInfoFunc.results.push({ node: parent.CloneSafeNode(getNodeNetInfoFunc.node), sys: getNodeNetInfoFunc.sysinfo, net: netinfo });
if (resultPendingCount == 0) { func(getNodeFunc.results, type); } if (resultPendingCount == 0) { func(getNodeFunc.results, type); }
}
getNodeNetInfoFunc.results = getNodeSysInfoFunc.results;
getNodeNetInfoFunc.nodeid = getNodeSysInfoFunc.nodeid;
getNodeNetInfoFunc.node = getNodeSysInfoFunc.node;
if ((err == null) && (docs != null) && (docs.length == 1)) { getNodeNetInfoFunc.sysinfo = docs[0]; }
// Query the database for network information
db.Get('if' + getNodeSysInfoFunc.nodeid, getNodeNetInfoFunc);
} }
getNodeNetInfoFunc.results = getNodeSysInfoFunc.results; getNodeSysInfoFunc.results = getNodeFunc.results;
getNodeNetInfoFunc.nodeid = getNodeSysInfoFunc.nodeid; getNodeSysInfoFunc.nodeid = getNodeFunc.nodeid;
getNodeNetInfoFunc.node = getNodeSysInfoFunc.node; getNodeSysInfoFunc.node = node;
if ((err == null) && (docs != null) && (docs.length == 1)) { getNodeNetInfoFunc.sysinfo = docs[0]; }
// Query the database for network information // Query the database for system information
db.Get('if' + getNodeSysInfoFunc.nodeid, getNodeNetInfoFunc); db.Get('si' + getNodeFunc.nodeid, getNodeSysInfoFunc);
} } else { resultPendingCount--; }
getNodeSysInfoFunc.results = getNodeFunc.results; if (resultPendingCount == 0) { func(getNodeFunc.results.join('\r\n'), type); }
getNodeSysInfoFunc.nodeid = getNodeFunc.nodeid; }
getNodeSysInfoFunc.node = node; getNodeFunc.results = results;
getNodeFunc.nodeid = docs[i]._id;
// Query the database for system information parent.GetNodeWithRights(domain, user, docs[i]._id, getNodeFunc);
db.Get('si' + getNodeFunc.nodeid, getNodeSysInfoFunc);
} else { resultPendingCount--; }
if (resultPendingCount == 0) { func(getNodeFunc.results.join('\r\n'), type); }
} }
getNodeFunc.results = results;
getNodeFunc.nodeid = docs[i]._id;
parent.GetNodeWithRights(domain, user, docs[i]._id, getNodeFunc);
} }
}); });
} else { } else {