Bugfixes and functional #7 & #9

- #7 needs to error check more
- both need to be cleaned up
This commit is contained in:
Logan Cusano
2023-06-11 04:40:40 -04:00
parent e8d68b2da7
commit f5e119d845
4 changed files with 18 additions and 32 deletions

View File

@@ -32,8 +32,6 @@ function returnNodeObjectFromRow(row) {
_location: row.location,
_nearbySystems: BufferToJson(row.nearbySystems),
_online: (row.online === 1) ? true : false,
_connected: (row.connected === 1) ? true : false,
_connection: (row.connection) ? row.connection : null,
});
}
@@ -62,6 +60,7 @@ function returnNodeObjectFromRows(rows) {
* @returns {connectionObject}
*/
async function returnConnectionObjectFromRow(row) {
if (Array.isArray(row)) row = row[0]
log.DEBUG("Connection row: ", row);
return new connectionObject({
_connection_id: row.connection_id,
@@ -111,6 +110,8 @@ exports.getOnlineNodes = (callback) => {
* @param callback Callback function
*/
async function getNodeInfoFromId(nodeId, callback = undefined) {
if (!nodeId) throw new Error("No node ID given when trying to fetch node");
log.DEBUG("Getting node from ID: ", nodeId);
const sqlQuery = `SELECT * FROM ${nodesTable} WHERE id = ${nodeId}`
const sqlResponse = await new Promise((recordResolve, recordReject) => {
@@ -161,8 +162,7 @@ exports.updateNodeInfo = async (nodeObject, callback = undefined) => {
ip = nodeObject.ip,
port = nodeObject.port,
location = nodeObject.location,
online = nodeObject.online,
connected = nodeObject.connected;
online = nodeObject.online
let queryParams = [],
nearbySystems = nodeObject.nearbySystems;
@@ -178,10 +178,6 @@ exports.updateNodeInfo = async (nodeObject, callback = undefined) => {
if (online || online === 1) queryParams.push(`online = 1`);
else queryParams.push(`online = 0`);
}
if (typeof connected === "boolean" || typeof connected === "number") {
if (online || online === 1) queryParams.push(`connected = 1`);
else queryParams.push(`connected = 0`);
}
let sqlQuery = `UPDATE ${nodesTable} SET`
if (!queryParams || queryParams.length === 0) return (callback) ? callback(undefined) : undefined;
@@ -276,7 +272,7 @@ exports.getConnectionByNodeId = async (nodeId, callback = undefined) => {
log.VERBOSE("SQL Response from checking connection: ", sqlResponse);
if (!sqlResponse) return (callback) ? callback(undefined) : undefined;
if (!sqlResponse | sqlResponse.length == 0) return (callback) ? callback(undefined) : undefined;
const newConnectionObject = await returnConnectionObjectFromRow(sqlResponse)
log.DEBUG("Connection Object from SQL Response: ", newConnectionObject);
return (callback) ? callback(newConnectionObject) : newConnectionObject;