Potential final fix for #30
This commit is contained in:
@@ -24,6 +24,8 @@ const nodeConnectionsTable = `${process.env.NODE_DB_NAME}.node_connections`;
|
||||
* @returns {nodeObject} The converted node object to be used downstream
|
||||
*/
|
||||
function returnNodeObjectFromRow(row) {
|
||||
if (!isNaN(row.online)) row.online = Boolean(row.online);
|
||||
else if (row.online == "true" || row.online == "false") row.online = (row.online == "true");
|
||||
return new nodeObject({
|
||||
_id: row.id,
|
||||
_name: row.name,
|
||||
@@ -31,7 +33,7 @@ function returnNodeObjectFromRow(row) {
|
||||
_port: row.port,
|
||||
_location: row.location,
|
||||
_nearbySystems: BufferToJson(row.nearbySystems),
|
||||
_online: (row.online === 1) ? true : false,
|
||||
_online: row.online,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -122,6 +124,7 @@ exports.getOnlineNodes = (callback) => {
|
||||
|
||||
// Call back the first (and theoretically only) row
|
||||
// Specify 0 so downstream functions don't have to worry about it
|
||||
if (!sqlResponse.length > 0) return (callback) ? callback(false) : false;
|
||||
return (callback) ? callback(await returnNodeObjectFromRow(sqlResponse[0])) : await returnNodeObjectFromRow(sqlResponse[0]);
|
||||
}
|
||||
exports.getNodeInfoFromId = getNodeInfoFromId
|
||||
@@ -136,9 +139,15 @@ exports.addNewNode = async (nodeObject, callback) => {
|
||||
ip = nodeObject.ip,
|
||||
port = nodeObject.port,
|
||||
location = nodeObject.location,
|
||||
nearbySystems = utils.JsonToBuffer(nodeObject.nearbySystems ?? {}),
|
||||
online = nodeObject.online
|
||||
const sqlQuery = `INSERT INTO ${nodesTable} (name, ip, port, location, nearbySystems, online) VALUES ('${name}', '${ip}', ${port}, '${location}', '${nearbySystems}', ${online})`;
|
||||
nearbySystems = utils.JsonToBuffer(nodeObject.nearbySystems ?? {})
|
||||
|
||||
var online = nodeObject.online;
|
||||
if (typeof online === "boolean" || typeof online === "number") {
|
||||
if (online) online = 1;
|
||||
else online = 0;
|
||||
}
|
||||
|
||||
const sqlQuery = `INSERT INTO ${nodesTable} (name, ip, port, location, nearbySystems, online) VALUES ('${name}', '${ip}', ${port}, '${location}', '${nearbySystems}', ${online})`;
|
||||
|
||||
const sqlResponse = await new Promise((recordResolve, recordReject) => {
|
||||
runSQL(sqlQuery, (rows) => {
|
||||
|
||||
Reference in New Issue
Block a user