Implemented functional method to add a new system to a new through web app
This commit is contained in:
@@ -117,6 +117,44 @@ exports.getNodeInfo = async (req, res) => {
|
||||
})
|
||||
}
|
||||
|
||||
/** Adds a specific system/preset on a given node
|
||||
*
|
||||
* @param {*} req Default express req from router
|
||||
* @param {*} res Defualt express res from router
|
||||
* @param {*} req.params.nodeId The Node ID to add the preset/system to
|
||||
* @param {*} req.body.systemName The name of the system to add
|
||||
* @param {*} req.body.mode The radio mode of the preset
|
||||
* @param {*} req.body.frequencies The frequencies of the preset
|
||||
* @param {*} req.body.trunkFile The trunk file to use for digital stations
|
||||
*/
|
||||
exports.addNodeSystem = async (req, res) => {
|
||||
if (!req.params.nodeId) return res.status(400).json("No id specified");
|
||||
if (!req.body.systemName) return res.status(400).json("No system specified");
|
||||
log.DEBUG("Adding system for node: ", req.params.nodeId, req.body);
|
||||
getNodeInfoFromId(req.params.nodeId, (node) => {
|
||||
const reqOptions = new requestOptions("/client/addPreset", "POST", node.ip, node.port);
|
||||
const reqBody = {
|
||||
'systemName': req.body.systemName,
|
||||
'mode': req.body.mode,
|
||||
'frequencies': req.body.frequencies,
|
||||
}
|
||||
if(digitalModes.includes(req.body.mode)) reqBody['trunkFile'] = req.body.trunkFile ?? 'none'
|
||||
|
||||
log.DEBUG("Request body for adding node system: ", reqBody, reqOptions);
|
||||
sendHttpRequest(reqOptions, JSON.stringify(reqBody), async (responseObj) => {
|
||||
if(responseObj){
|
||||
// Good
|
||||
log.DEBUG("Response from adding node system: ", reqBody, responseObj);
|
||||
return res.sendStatus(200)
|
||||
} else {
|
||||
// Bad
|
||||
log.DEBUG("No Response from adding Node system");
|
||||
return res.status(400).json("No Response from adding Node, could be offline");
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/** Updates a specific system/preset on a given node
|
||||
*
|
||||
* @param {*} req Default express req from router
|
||||
@@ -144,11 +182,11 @@ exports.updateNodeSystem = async (req, res) => {
|
||||
sendHttpRequest(reqOptions, JSON.stringify(reqBody), async (responseObj) => {
|
||||
if(responseObj){
|
||||
// Good
|
||||
log.DEBUG("Response from updating node: ", reqBody, responseObj);
|
||||
log.DEBUG("Response from updating node system: ", reqBody, responseObj);
|
||||
return res.sendStatus(200)
|
||||
} else {
|
||||
// Bad
|
||||
log.DEBUG("No Response from updating Node");
|
||||
log.DEBUG("No Response from updating Node system");
|
||||
return res.status(400).json("No Response from updating Node, could be offline");
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user