From e4c4d0e3d7dc7be7ac233cd6c9b90ae92fb1a5b3 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Tue, 17 Jul 2018 02:43:31 +0000 Subject: [server] Fixed eslint errors. (Standard ESLint is used) --- server/api/backends.js | 127 +++++++++++++++++++++++++------------------------ 1 file changed, 64 insertions(+), 63 deletions(-) (limited to 'server/api/backends.js') 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') + }) + } } -- cgit v1.2.3-55-g7522