summaryrefslogtreecommitdiffstats
path: root/server/api/backends.js
diff options
context:
space:
mode:
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
}
}