Implement functioning method to update systems on web app
This commit is contained in:
@@ -94,10 +94,12 @@ exports.checkConfig = async function checkConfig() {
|
||||
}
|
||||
|
||||
/** Check in with the server
|
||||
* If the bot has a saved ID, check in with the server to update any information or just check back in
|
||||
* If the bot has a saved ID, check in with the server to get any updated information or just check back in
|
||||
* If the bot does not have a saved ID, it will attempt to request a new ID from the server
|
||||
*
|
||||
* @param {boolean} init If set to true, the client will update the server to it's config, instead of taking the server's config
|
||||
*/
|
||||
exports.checkIn = async () => {
|
||||
exports.checkIn = async (init = false) => {
|
||||
let reqOptions;
|
||||
await this.checkConfig();
|
||||
runningClientConfig.online = true;
|
||||
@@ -134,7 +136,8 @@ exports.checkIn = async () => {
|
||||
}
|
||||
else {
|
||||
// ID is in the config, checking in with the server
|
||||
reqOptions = new requestOptions("/nodes/nodeCheckIn", "POST");
|
||||
if (init) reqOptions = new requestOptions(`/nodes/${runningClientConfig.id}`, "PUT");
|
||||
else reqOptions = new requestOptions(`/nodes/nodeCheckIn/${runningClientConfig.id}`, "POST");
|
||||
sendHttpRequest(reqOptions, JSON.stringify(runningClientConfig), (responseObject) => {
|
||||
log.DEBUG("Check In Respose: ", responseObject);
|
||||
// Check if the server responded
|
||||
@@ -178,7 +181,8 @@ exports.requestCheckIn = async (req, res) => {
|
||||
* This is the endpoint wrapper to get the presets object
|
||||
*/
|
||||
exports.getPresets = async (req, res) => {
|
||||
return res.status(200).json(getPresets());
|
||||
runningClientConfig.nearbySystems = getPresets();
|
||||
return res.status(200).json(runningClientConfig.nearbySystems);
|
||||
}
|
||||
|
||||
/** Controller for the /client/updatePreset endpoint
|
||||
@@ -187,6 +191,7 @@ exports.getPresets = async (req, res) => {
|
||||
exports.updatePreset = async (req, res) => {
|
||||
checkBodyForPresetFields(req, res, () => {
|
||||
updatePreset(req.body.systemName, () => {
|
||||
runningClientConfig.nearbySystems = getPresets();
|
||||
return res.sendStatus(200);
|
||||
}, {frequencies: req.body.frequencies, mode: req.body.mode, trunkFile: req.body.trunkFile});
|
||||
})
|
||||
@@ -198,6 +203,7 @@ exports.updatePreset = async (req, res) => {
|
||||
exports.addNewPreset = async (req, res) => {
|
||||
checkBodyForPresetFields(req, res, () => {
|
||||
addNewPreset(req.body.systemName, req.body.frequencies, req.body.mode, () => {
|
||||
runningClientConfig.nearbySystems = getPresets();
|
||||
return res.sendStatus(200);
|
||||
}, req.body.trunkFile);
|
||||
});
|
||||
@@ -210,6 +216,7 @@ exports.removePreset = async (req, res) => {
|
||||
checkBodyForPresetFields(req, res, () => {
|
||||
if (!req.body.systemName) return res.status("500").json({"message": "You must specify a system name to delete, this must match exactly to how the system name is saved."})
|
||||
removePreset(req.body.systemName, () => {
|
||||
runningClientConfig.nearbySystems = getPresets();
|
||||
return res.sendStatus(200);
|
||||
}, req.body.trunkFile);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user