summaryrefslogtreecommitdiffstats
path: root/server/api/backends.js
diff options
context:
space:
mode:
authorJannik Schönartz2018-07-17 04:43:31 +0200
committerJannik Schönartz2018-07-17 04:43:31 +0200
commite4c4d0e3d7dc7be7ac233cd6c9b90ae92fb1a5b3 (patch)
tree0c40021f77fea9688449c9c4d6e6222a809ec3d6 /server/api/backends.js
parent[webapp] renamed components (diff)
downloadbas-e4c4d0e3d7dc7be7ac233cd6c9b90ae92fb1a5b3.tar.gz
bas-e4c4d0e3d7dc7be7ac233cd6c9b90ae92fb1a5b3.tar.xz
bas-e4c4d0e3d7dc7be7ac233cd6c9b90ae92fb1a5b3.zip
[server] Fixed eslint errors. (Standard ESLint is used)
Diffstat (limited to 'server/api/backends.js')
-rw-r--r--server/api/backends.js127
1 files changed, 64 insertions, 63 deletions
diff --git a/server/api/backends.js b/server/api/backends.js
index e3e6014..fd2657b 100644
--- a/server/api/backends.js
+++ b/server/api/backends.js
@@ -1,75 +1,76 @@
/* global __appdir */
-const path = require('path');
-const ExternalBackends = require(path.join(__appdir, 'lib', 'external-backends', 'external-backends.js'));
-var db = require(path.join(__appdir, 'lib', 'sequelize'));
+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 = {
- getCredentialsByType: function(req, res) {
- const backendType = req.query.type;
- const b = new ExternalBackends();
- const instance = b.getInstance(backendType);
- res.status(200).send(instance.getCredentials());
- },
+ getCredentialsByType: function (req, res) {
+ const backendType = req.query.type
+ const b = new ExternalBackends()
+ const instance = b.getInstance(backendType)
+ if (instance === null) {
+ res.status(500).send({ auth: false, status: 'TYPE_INVALID', error_message: 'The provided backend type is invalid.' })
+ }
+
+ res.status(200).send(instance.getCredentials())
+ },
- getBackendInfoById: function(req, res) {
- // TODO: Test (Not used for now) needed for edit // TODO: // TODO:
- const backendId = req.query.id;
- db.backend.findOne({ where: { id: backendId } }).then(backend => {
- const b = {
- backendId: backendId,
- backendName: backend.name,
- backendType: backend.type,
- backendCredentials: backend.credentials
- }
- res.status(200).send(b);
- });
- },
+ getBackendInfoById: function (req, res) {
+ const backendId = req.query.id
+ db.backend.findOne({ where: { id: backendId } }).then(backend => {
+ const b = {
+ backendId: backendId,
+ backendName: backend.name,
+ backendType: backend.type,
+ backendCredentials: backend.credentials
+ }
+ res.status(200).send(b)
+ })
+ },
- getBackendTypes: function(req, res) {
+ getBackendTypes: function (req, res) {
+ const backends = new ExternalBackends()
+ var files = backends.getBackends()
- const backends = new ExternalBackends();
- var files = backends.getBackends();
-
- for (var i = 0; i < files.length; i++) {
-
- // Cut off -backends.js
- files[i] = files[i].slice(0, -11);
- }
-
- res.status(200).send(files);
- },
+ for (var i = 0; i < files.length; i++) {
+ // Cut off -backends.js
+ files[i] = files[i].slice(0, -11)
+ }
- getBackendList: function(req, res) {
- db.backend.findAll({
- attributes: ['id', 'name', 'type']
- }).then(function (backends) {
- res.status(200).send(backends);
- });
- },
+ res.status(200).send(files)
+ },
- // POST REQUESTS
- saveBackend: function(req, res) {
- // Save credentials in the db.
- const formData = req.body;
- const credentialString = JSON.stringify(formData.backendCredentials);
+ getBackendList: function (req, res) {
+ db.backend.findAll({
+ attributes: ['id', 'name', 'type']
+ }).then(function (backends) {
+ res.status(200).send(backends)
+ })
+ },
- if (formData.backendId == 0) {
- // Insert new backend in the db.
- db.backend.create({ name: formData.backendName, type: formData.backendType, credentials: credentialString });
- } else {
- // Update an existing backend in the db.
- db.backend.update({ name: formData.backendName, type: formData.backendType, credentials: credentialString }, {where: {id: formData.backendId} });
- }
- //db.backend.findOne({})
-
- res.status(200).send('success');
- },
+ // POST REQUESTS
+ saveBackend: function (req, res) {
+ // Save credentials in the db.
+ const formData = req.body
+ const credentialString = JSON.stringify(formData.backendCredentials)
- deleteBackendById: function(req, res) {
- const backendId = req.body.id;
-
- db.backend.destroy({ where: { id: backendId } }).then(function() {
- res.status(200).send('success');
- });
+ if (formData.backendId === 0) {
+ // Insert new backend in the db.
+ db.backend.create({ name: formData.backendName, type: formData.backendType, credentials: credentialString })
+ } else {
+ // Update an existing backend in the db.
+ db.backend.update({ name: formData.backendName, type: formData.backendType, credentials: credentialString }, { where: { id: formData.backendId } })
}
+ // db.backend.findOne({})
+
+ res.status(200).send('success')
+ },
+
+ deleteBackendById: function (req, res) {
+ const backendId = req.body.id
+
+ db.backend.destroy({ where: { id: backendId } }).then(function () {
+ res.status(200).send('success')
+ })
+ }
}