summaryrefslogtreecommitdiffstats
path: root/server/api/backends.js
diff options
context:
space:
mode:
authorJannik Schönartz2018-07-26 15:09:54 +0200
committerJannik Schönartz2018-07-26 15:09:54 +0200
commitdfbc9e183af3fbd28dc72f386b97f8df7b3de7c1 (patch)
tree95b50a0dec8f5a15bd3f6e124c6b14133590597a /server/api/backends.js
parent[server/ipxe-loader] Fixed the script for booting a pxe-linux. (diff)
downloadbas-dfbc9e183af3fbd28dc72f386b97f8df7b3de7c1.tar.gz
bas-dfbc9e183af3fbd28dc72f386b97f8df7b3de7c1.tar.xz
bas-dfbc9e183af3fbd28dc72f386b97f8df7b3de7c1.zip
[server/backends] Added iDoII Backend. Implemented a checkConnection method for each individual backend. Switches in backends can now have recursive elements. They are only shown if the switch is set to true.
Diffstat (limited to 'server/api/backends.js')
-rw-r--r--server/api/backends.js40
1 files changed, 27 insertions, 13 deletions
diff --git a/server/api/backends.js b/server/api/backends.js
index b744bd2..a5d1233 100644
--- a/server/api/backends.js
+++ b/server/api/backends.js
@@ -47,19 +47,21 @@ module.exports = {
})
},
- checkConnection: function (req, res) {
- var x = Math.floor(Math.random() * Math.floor(2))
- var y = ''
- if (x === 0) {
- y = 'success'
- } else {
- y = 'error'
- }
- var w = 'Oh noes! An error occurred.'
- var z = Math.floor(Math.random() * Math.floor(5000))
-
-
- setTimeout(function() { res.status(200).send({ status: y, msg: w }) }, 0)
+ checkConnectionById: function (req, res) {
+ const backendId = req.query.id
+ db.backend.findOne({ where: { id: backendId } }).then(backend => {
+ const bCredentials = {
+ backendId: backendId,
+ backendName: backend.name,
+ backendType: backend.type,
+ backendCredentials: backend.credentials
+ }
+ const b = new ExternalBackends()
+ const instance = b.getInstance(bCredentials.backendType)
+ instance.checkConnection().then(connection => {
+ res.status(200).send({ success: connection.success, msg: connection.msg })
+ })
+ })
},
// POST REQUESTS
@@ -86,5 +88,17 @@ module.exports = {
db.backend.destroy({ where: { id: backendIds } }).then(function () {
res.status(200).send('success')
})
+ },
+
+ checkConnection: function (req, res) {
+ const type = req.body.backendType
+ // const credentials = req.body.backendCredentials
+
+ const b = new ExternalBackends()
+ const instance = b.getInstance(type)
+ instance.checkConnection().then(connection => {
+ res.status(200).send({ success: connection.success, msg: connection.msg })
+ })
+ // TODO: Set credentials
}
}