Update API and add webapp saving

This commit is contained in:
Logan Cusano
2023-07-16 18:56:47 -04:00
parent e27dd9d9cb
commit 5428ac6144
4 changed files with 103 additions and 34 deletions

View File

@@ -110,8 +110,8 @@ exports.newNode = async (req, res) => {
* @param {*} res Defualt express res from router
*/
exports.getNodeInfo = async (req, res) => {
if (!req.query.id) return res.status(400).json("No id specified");
getNodeInfoFromId(req.query.id, (nodeInfo) => {
if (!req.params.id) return res.status(400).json("No id specified");
getNodeInfoFromId(req.params.id, (nodeInfo) => {
res.status(200).json(nodeInfo);
})
}
@@ -121,9 +121,9 @@ exports.getNodeInfo = async (req, res) => {
* @param {*} req Default express req from router
* @param {*} res Defualt express res from router
*/
exports.nodeCheckIn = async (req, res) => {
if (!req.body.id) return res.status(400).json("No id specified");
getNodeInfoFromId(req.body.id, (nodeInfo) => {
exports.updateExistingNode = async = (req, res) => {
if (!req.params.nodeId) return res.status(400).json("No id specified");
getNodeInfoFromId(req.params.nodeId, (nodeInfo) => {
let checkInObject = {};
// Convert the online status to a boolean to be worked with
log.DEBUG("REQ Body: ", req.body);
@@ -163,9 +163,9 @@ exports.nodeCheckIn = async (req, res) => {
// If no changes are made tell the client
if (!isObjectUpdated) return res.status(200).json("No keys updated");
log.INFO("Updating the following keys for ID: ", req.body.id, checkInObject);
log.INFO("Updating the following keys for ID: ", req.params.nodeId, checkInObject);
checkInObject._id = req.body.id;
checkInObject._id = req.params.nodeId;
checkInObject = new nodeObject(checkInObject);
if (!nodeInfo) {
@@ -182,6 +182,24 @@ exports.nodeCheckIn = async (req, res) => {
});
}
/** Allows the bots to check in and get any updates from the server
*
* @param {*} req Default express req from router
* @param {*} res Defualt express res from router
*/
exports.nodeCheckIn = async (req, res) => {
if (!req.params.nodeId) return res.status(400).json("No id specified");
getNodeInfoFromId(req.params.nodeId, (nodeInfo) => {
if (!nodeInfo.online) {
nodeInfo.online = true;
updateNodeInfo(nodeInfo, () => {
return res.status(200).json(nodeInfo);
})
}
else return res.status(200).json(nodeInfo);
});
}
/**
* Requests a specific node to check in with the server, if it's online
*