if no nodes return nothing for getDeviceDetails #6637

Signed-off-by: si458 <simonsmith5521@gmail.com>

si458 committed Jan 3, 2025 at 16:59 UTC e66776c5da2c4f90a380e71ece368c63ba29804b
1 file changed +38 -34
meshuser.js
+38 -34
@@ -8049,42 +8049,46 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
8049 parent.common.unEscapeAllLinksFieldName(docs);
8050
8051 var results = [], resultPendingCount = 0;
8052 - for (i in docs) {
8053 - // Check device links, if a link points to an unknown user, remove it.
8054 - parent.cleanDevice(docs[i]);
8055 -
8056 - // Fetch the node from the database
8057 - resultPendingCount++;
8058 - const getNodeFunc = function (node, rights, visible) {
8059 - if ((node != null) && (visible == true)) {
8060 - const getNodeSysInfoFunc = function (err, docs) {
8061 - const getNodeNetInfoFunc = function (err, docs) {
8062 - var netinfo = null;
8063 - if ((err == null) && (docs != null) && (docs.length == 1)) { netinfo = docs[0]; }
8064 - resultPendingCount--;
8065 - getNodeNetInfoFunc.results.push({ node: parent.CloneSafeNode(getNodeNetInfoFunc.node), sys: getNodeNetInfoFunc.sysinfo, net: netinfo });
8066 - if (resultPendingCount == 0) { func(getNodeFunc.results, type); }
8052 + if (docs.length == 0) { // no results return blank array
8053 + func(docs, type);
8054 + } else {
8055 + for (i in docs) {
8056 + // Check device links, if a link points to an unknown user, remove it.
8057 + parent.cleanDevice(docs[i]);
8058 +
8059 + // Fetch the node from the database
8060 + resultPendingCount++;
8061 + const getNodeFunc = function (node, rights, visible) {
8062 + if ((node != null) && (visible == true)) {
8063 + const getNodeSysInfoFunc = function (err, docs) {
8064 + const getNodeNetInfoFunc = function (err, docs) {
8065 + var netinfo = null;
8066 + if ((err == null) && (docs != null) && (docs.length == 1)) { netinfo = docs[0]; }
8067 + resultPendingCount--;
8068 + getNodeNetInfoFunc.results.push({ node: parent.CloneSafeNode(getNodeNetInfoFunc.node), sys: getNodeNetInfoFunc.sysinfo, net: netinfo });
8069 + if (resultPendingCount == 0) { func(getNodeFunc.results, type); }
8070 + }
8071 + getNodeNetInfoFunc.results = getNodeSysInfoFunc.results;
8072 + getNodeNetInfoFunc.nodeid = getNodeSysInfoFunc.nodeid;
8073 + getNodeNetInfoFunc.node = getNodeSysInfoFunc.node;
8074 + if ((err == null) && (docs != null) && (docs.length == 1)) { getNodeNetInfoFunc.sysinfo = docs[0]; }
8075 +
8076 + // Query the database for network information
8077 + db.Get('if' + getNodeSysInfoFunc.nodeid, getNodeNetInfoFunc);
8078 }
8068 - getNodeNetInfoFunc.results = getNodeSysInfoFunc.results;
8069 - getNodeNetInfoFunc.nodeid = getNodeSysInfoFunc.nodeid;
8070 - getNodeNetInfoFunc.node = getNodeSysInfoFunc.node;
8071 - if ((err == null) && (docs != null) && (docs.length == 1)) { getNodeNetInfoFunc.sysinfo = docs[0]; }
8079 + getNodeSysInfoFunc.results = getNodeFunc.results;
8080 + getNodeSysInfoFunc.nodeid = getNodeFunc.nodeid;
8081 + getNodeSysInfoFunc.node = node;
8082
8073 - // Query the database for network information
8074 - db.Get('if' + getNodeSysInfoFunc.nodeid, getNodeNetInfoFunc);
8075 - }
8076 - getNodeSysInfoFunc.results = getNodeFunc.results;
8077 - getNodeSysInfoFunc.nodeid = getNodeFunc.nodeid;
8078 - getNodeSysInfoFunc.node = node;
8079 -
8080 - // Query the database for system information
8081 - db.Get('si' + getNodeFunc.nodeid, getNodeSysInfoFunc);
8082 - } else { resultPendingCount--; }
8083 - if (resultPendingCount == 0) { func(getNodeFunc.results.join('\r\n'), type); }
8084 - }
8085 - getNodeFunc.results = results;
8086 - getNodeFunc.nodeid = docs[i]._id;
8087 - parent.GetNodeWithRights(domain, user, docs[i]._id, getNodeFunc);
8083 + // Query the database for system information
8084 + db.Get('si' + getNodeFunc.nodeid, getNodeSysInfoFunc);
8085 + } else { resultPendingCount--; }
8086 + if (resultPendingCount == 0) { func(getNodeFunc.results.join('\r\n'), type); }
8087 + }
8088 + getNodeFunc.results = results;
8089 + getNodeFunc.nodeid = docs[i]._id;
8090 + parent.GetNodeWithRights(domain, user, docs[i]._id, getNodeFunc);
8091 + }
8092 }
8093 });
8094 } else {