From e8cb6c497b4cc1cdd96866b66dba7a650a232908 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sat, 25 Feb 2023 14:49:40 -0500 Subject: [PATCH] Updated callbacks to all return --- controllers/adminController.js | 10 +++++----- utilities/httpRequests.js | 4 ++-- utilities/mysqlHandler.js | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/controllers/adminController.js b/controllers/adminController.js index f630af4..480329b 100644 --- a/controllers/adminController.js +++ b/controllers/adminController.js @@ -20,7 +20,7 @@ async function getPresetsOfOnlineNodes(callback) { systems[onlineNode.id] = utils.BufferToJson(onlineNode.nearbySystems); }); - callback(systems); + return callback(systems); }); } @@ -31,7 +31,7 @@ async function requestNodeListenToPreset(preset, nodeId, callback) { "channelID": discordConfig.channelID, "presetName": preset }), (responseObject) => { - callback(responseObject) + return callback(responseObject) }); }) } @@ -46,7 +46,7 @@ async function getNodeBotStatus(nodeId, callback) { else { // Bot is free } - callback(responseObject); + return callback(responseObject); }); }); } @@ -58,13 +58,13 @@ async function requestNodeLeaveServer(nodeId, callback) { mysqlHandler.getNodeInfoFromId(nodeId, (nodeObject) =>{ reqOptions = new requests.requestOptions("/bot/leave", "POST", nodeObject.ip, nodeObject.port); requests.sendHttpRequest(reqOptions, JSON.stringify({}), (responseObject) => { - callback(responseObject); + return callback(responseObject); }); }); } else { // Bot is free - callback(false); + return callback(false); } }) } diff --git a/utilities/httpRequests.js b/utilities/httpRequests.js index 4fef264..b64747c 100644 --- a/utilities/httpRequests.js +++ b/utilities/httpRequests.js @@ -49,7 +49,7 @@ exports.sendHttpRequest = function sendHttpRequest(requestOptions, data, callbac } log.DEBUG("Response Object: ", responseObject); - callback(responseObject); + return callback(responseObject); }) }).on('error', err => { log.ERROR('Error: ', err.message) @@ -58,7 +58,7 @@ exports.sendHttpRequest = function sendHttpRequest(requestOptions, data, callbac if (requestOptions.timeout) { req.setTimeout(requestOptions.timeout, () => { - callback(false); + return callback(false); }); } diff --git a/utilities/mysqlHandler.js b/utilities/mysqlHandler.js index 7a1225b..adc1412 100644 --- a/utilities/mysqlHandler.js +++ b/utilities/mysqlHandler.js @@ -19,7 +19,7 @@ connection.connect() exports.getAllNodes = (callback) => { const sqlQuery = `SELECT * FROM ${nodesTable}` runSQL(sqlQuery, (rows) => { - callback(rows); + return callback(rows); }) } @@ -29,7 +29,7 @@ exports.getAllNodes = (callback) => { exports.getOnlineNodes = (callback) => { const sqlQuery = `SELECT * FROM ${nodesTable} WHERE online = 1;` runSQL(sqlQuery, (rows) => { - callback(rows); + return callback(rows); }) } @@ -42,7 +42,7 @@ exports.getNodeInfoFromId = (nodeId, callback) => { runSQL(sqlQuery, (rows) => { // Call back the first (and theoretically only) row // Specify 0 so downstream functions don't have to worry about it - callback(rows[0]); + return callback(rows[0]); }) } @@ -61,7 +61,7 @@ exports.addNewNode = (nodeObject, callback) => { const sqlQuery = `INSERT INTO ${nodesTable} (name, ip, port, location, nearbySystems, online) VALUES ('${name}', '${ip}', ${port}, '${location}', '${nearbySystems}', ${online})`; runSQL(sqlQuery, (rows) => { - callback(rows); + return callback(rows); }) } @@ -112,8 +112,8 @@ exports.updateNodeInfo = (nodeObject, callback) => { sqlQuery = `${sqlQuery} WHERE id = ${nodeObject.id};` runSQL(sqlQuery, (rows) => { - if (rows.affectedRows === 1) callback(true); - else callback(rows); + if (rows.affectedRows === 1) return callback(true); + else return callback(rows); }) }