summaryrefslogtreecommitdiffstats
path: root/server/api/backends.js
diff options
context:
space:
mode:
authorJannik Schönartz2018-07-30 05:06:35 +0200
committerJannik Schönartz2018-07-30 05:06:35 +0200
commitce9a81e6361504ea68286cd9fda72391d0aaba12 (patch)
tree38f69c5e33960d8ac6357e2601c9f34b7afec831 /server/api/backends.js
parent[webapp] delete placeholder modules (diff)
downloadbas-ce9a81e6361504ea68286cd9fda72391d0aaba12.tar.gz
bas-ce9a81e6361504ea68286cd9fda72391d0aaba12.tar.xz
bas-ce9a81e6361504ea68286cd9fda72391d0aaba12.zip
[server] Changed old modules to the new rounter restructure.
Diffstat (limited to 'server/api/backends.js')
-rw-r--r--server/api/backends.js48
1 files changed, 31 insertions, 17 deletions
diff --git a/server/api/backends.js b/server/api/backends.js
index 3b9551e..e4d3ff6 100644
--- a/server/api/backends.js
+++ b/server/api/backends.js
@@ -3,7 +3,8 @@ const path = require('path')
const ExternalBackends = require(path.join(__appdir, 'lib', 'external-backends', 'external-backends.js'))
var db = require(path.join(__appdir, 'lib', 'sequelize'))
-module.exports = {
+// GET requests
+module.exports.get = {
getCredentialsByType: function (req, res) {
const backendType = req.query.type
const b = new ExternalBackends()
@@ -14,7 +15,7 @@ module.exports = {
res.status(200).send(instance.getCredentials())
},
- getBackendInfoById: function (req, res) {
+ getInfoById: function (req, res) {
const backendId = req.query.id
db.backend.findOne({ where: { id: backendId } }).then(backend => {
const b = {
@@ -27,7 +28,7 @@ module.exports = {
})
},
- getBackendTypes: function (req, res) {
+ getTypes: function (req, res) {
const backends = new ExternalBackends()
var files = backends.getBackends()
@@ -39,7 +40,7 @@ module.exports = {
res.status(200).send(files)
},
- getBackendList: function (req, res) {
+ getList: function (req, res) {
db.backend.findAll({
attributes: ['id', 'name', 'type']
}).then(function (backends) {
@@ -62,10 +63,12 @@ module.exports = {
res.status(200).send({ success: connection.success, msg: connection.msg })
})
})
- },
+ }
+}
- // POST REQUESTS
- saveBackend: function (req, res) {
+// POST requests
+module.exports.post = {
+ save: function (req, res) {
// Save credentials in the db.
const formData = req.body
const credentialString = JSON.stringify(formData.backendCredentials)
@@ -82,7 +85,7 @@ module.exports = {
res.status(200).send('success')
},
- deleteBackends: function (req, res) {
+ delete: function (req, res) {
const backendIds = req.body.id
db.backend.destroy({ where: { id: backendIds } }).then(function () {
@@ -90,15 +93,26 @@ module.exports = {
})
},
+ // If id is set the backend connection in the db is testest.
+ // Else backendinfo has to be set manually, to test unsaved connections.
checkConnection: function (req, res) {
- const type = req.body.backendType
- // const credentials = req.body.backendCredentials
+ const id = req.body.id
- 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
+ var getBackend = null
+ if (id) getBackend = db.backend.findOne({ where: { id: id } })
+ else getBackend = new Promise(resolve => resolve(req.body))
+
+ getBackend.then(backend => {
+ var bCredentials = {
+ type: backend.type,
+ credentials: backend.credentials
+ }
+ // Creating the backend instance and calling the specific checkConnection.
+ const b = new ExternalBackends()
+ const instance = b.getInstance(bCredentials.type)
+ instance.checkConnection(bCredentials).then(connection => {
+ res.status(200).send({ success: connection.success, msg: connection.msg })
+ })
+ })
}
-}
+} \ No newline at end of file