summaryrefslogtreecommitdiffstats
path: root/server/api
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
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')
-rw-r--r--server/api/backends.js127
-rw-r--r--server/api/clients.js34
-rw-r--r--server/api/ipxe-loader.js10
-rw-r--r--server/api/locations.js20
-rw-r--r--server/api/permissions.js42
-rw-r--r--server/api/user.js52
6 files changed, 143 insertions, 142 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')
+ })
+ }
}
diff --git a/server/api/clients.js b/server/api/clients.js
index 53aeb9d..f7fe455 100644
--- a/server/api/clients.js
+++ b/server/api/clients.js
@@ -1,20 +1,20 @@
/* global __appdir */
-var path = require('path');
-var db = require(path.join(__appdir, 'lib', 'sequelize'));
+var path = require('path')
+var db = require(path.join(__appdir, 'lib', 'sequelize'))
module.exports = {
- get: function(req, res) {
- //db.sequelize.authenticate()
- //.then(() => { console.log('Connection has been established successfully.'); })
- //.catch(err => { console.error('Unable to connect to the database:', err); });
-
- //db.users2.create({ username: "wasd", password: "wasd", email: "w@a.de", name: "wa"});
- db.users2.findOne({ where: { username: 'wasd' } }).then(user => {
- console.log(user.get('username'));
- });
- res.end();
- },
- post: function(req, res) {
-
- }
-} \ No newline at end of file
+ get: function (req, res) {
+ // db.sequelize.authenticate()
+ // .then(() => { console.log('Connection has been established successfully.'); })
+ // .catch(err => { console.error('Unable to connect to the database:', err); });
+
+ // db.users2.create({ username: "wasd", password: "wasd", email: "w@a.de", name: "wa"});
+ db.users2.findOne({ where: { username: 'wasd' } }).then(user => {
+ console.log(user.get('username'))
+ })
+ res.end()
+ },
+ post: function (req, res) {
+
+ }
+}
diff --git a/server/api/ipxe-loader.js b/server/api/ipxe-loader.js
index 57c152f..e75ce72 100644
--- a/server/api/ipxe-loader.js
+++ b/server/api/ipxe-loader.js
@@ -1,7 +1,7 @@
module.exports = {
- loadScript: function(req, res) {
- res.setHeader('content-type', 'text/plain');
- res.status(200).send(`#!ipxe
+ loadScript: function (req, res) {
+ res.setHeader('content-type', 'text/plain')
+ res.status(200).send(`#!ipxe
dhcp
:start
@@ -37,6 +37,6 @@ boot
:sh
shell
-goto start`);
- }
+goto start`)
+ }
}
diff --git a/server/api/locations.js b/server/api/locations.js
index c72ff93..7595837 100644
--- a/server/api/locations.js
+++ b/server/api/locations.js
@@ -1,13 +1,13 @@
-/* global __appdir */
-//var path = require('path');
+// /* global __appdir */
+// var path = require('path');
module.exports = {
- get: function(req, res) {
- console.log('You successfully called an authentication call!');
- res.send('You successfully called an authentication call!');
- },
- post: function(req, res) {
- console.log('You successfully called an unauthentication call!');
- res.send('You successfully called an unauthentication call!');
- }
+ get: function (req, res) {
+ console.log('You successfully called an authentication call!')
+ res.send('You successfully called an authentication call!')
+ },
+ post: function (req, res) {
+ console.log('You successfully called an unauthentication call!')
+ res.send('You successfully called an unauthentication call!')
+ }
}
diff --git a/server/api/permissions.js b/server/api/permissions.js
index bf24462..52cd110 100644
--- a/server/api/permissions.js
+++ b/server/api/permissions.js
@@ -1,28 +1,28 @@
/* global __appdir */
-var path = require('path');
-var db = require(path.join(__appdir, 'lib', 'sequelize'));
+var path = require('path')
+var db = require(path.join(__appdir, 'lib', 'sequelize'))
module.exports = {
- // Return ID, Description and Name of a given RoleID
- getRoleById: function(req, res) {
- var roleid = req.params.roleid;
- db.role.findById(roleid).then(role_db => {
- var role = { };
- role.id = role_db.id;
- role.descr = role_db.descr;
- role.name = role_db.name;
- res.status(200).send(role);
- });
- },
- // Return all RoleIDs associated to a given UserID
- getRolesByUserid: function(req, res) {
- // var userid = req.query.userid;
- // the usersxroles (and rolesxpermissions) models first have to get created
- /* db.usersxroles.findAndCountAll({ where: { id: userid }, attributes: ['roleid'] }).then(roles_db => {
+ // Return ID, Description and Name of a given RoleID
+ getRoleById: function (req, res) {
+ var roleid = req.params.roleid
+ db.role.findById(roleid).then(robeDb => {
+ var role = { }
+ role.id = robeDb.id
+ role.descr = robeDb.descr
+ role.name = robeDb.name
+ res.status(200).send(role)
+ })
+ },
+ // Return all RoleIDs associated to a given UserID
+ getRolesByUserid: function (req, res) {
+ // var userid = req.query.userid;
+ // the usersxroles (and rolesxpermissions) models first have to get created
+ /* db.usersxroles.findAndCountAll({ where: { id: userid }, attributes: ['roleid'] }).then(roles_db => {
var result = { };
result.count = roles_db.count;
result.roles = roles_db.rows;
res.status(200).send(result);
- });*/
- }
-} \ No newline at end of file
+ }); */
+ }
+}
diff --git a/server/api/user.js b/server/api/user.js
index e42e26b..0565d58 100644
--- a/server/api/user.js
+++ b/server/api/user.js
@@ -1,30 +1,30 @@
/* global __appdir */
-var path = require('path');
-//var db = require(path.join(__appdir, 'lib', 'database')).connectionPool;
-var db = require(path.join(__appdir, 'lib', 'sequelize'));
-var jwt = require('jsonwebtoken');
+var path = require('path')
+// var db = require(path.join(__appdir, 'lib', 'database')).connectionPool;
+var db = require(path.join(__appdir, 'lib', 'sequelize'))
+var jwt = require('jsonwebtoken')
module.exports = {
- info: function(req, res) {
- // Because veryfyToken was succesfully excecuted the request has the attribute token.
- const token = req.token;
- // Decode the token.
- var decoded = jwt.decode(token, {complete: true});
- var userid = decoded.payload.user.id;
-
- //db.query('SELECT * FROM users WHERE id=?', [userid], function(err, rows) {
- db.user.findOne({ where: { id: userid } }).then(user_db => {
- //if (err) return res.status(500).send({ auth: false, status: 'DATABASE_ERROR', error_message: 'SQL query failed.' });
- //user.id = rows[0].id;
- //user.username = rows[0].username;
- //user.email = rows[0].email;
- //user.name = rows[0].name;
- var user = { };
- user.id = user_db.id;
- user.username = user_db.username;
- user.email = user_db.email;
- user.name = user_db.name;
- res.status(200).send(user);
- });
- }
+ info: function (req, res) {
+ // Because veryfyToken was succesfully excecuted the request has the attribute token.
+ const token = req.token
+ // Decode the token.
+ var decoded = jwt.decode(token, {complete: true})
+ var userid = decoded.payload.user.id
+
+ // db.query('SELECT * FROM users WHERE id=?', [userid], function(err, rows) {
+ db.user.findOne({ where: { id: userid } }).then(userDb => {
+ // if (err) return res.status(500).send({ auth: false, status: 'DATABASE_ERROR', error_message: 'SQL query failed.' });
+ // user.id = rows[0].id;
+ // user.username = rows[0].username;
+ // user.email = rows[0].email;
+ // user.name = rows[0].name;
+ var user = { }
+ user.id = userDb.id
+ user.username = userDb.username
+ user.email = userDb.email
+ user.name = userDb.name
+ res.status(200).send(user)
+ })
+ }
}