summaryrefslogtreecommitdiffstats
path: root/server/api
diff options
context:
space:
mode:
authorJannik Schönartz2018-07-02 21:52:25 +0200
committerJannik Schönartz2018-07-02 21:52:25 +0200
commitaa4e552a03657a63922f5cd085431257c183f458 (patch)
treefc8cd63129bb54b06326c11847a9731fe70f1b33 /server/api
downloadbas-aa4e552a03657a63922f5cd085431257c183f458.tar.gz
bas-aa4e552a03657a63922f5cd085431257c183f458.tar.xz
bas-aa4e552a03657a63922f5cd085431257c183f458.zip
[server] Initial commit to add the node server stuff.
Diffstat (limited to 'server/api')
-rw-r--r--server/api/clients.js20
-rw-r--r--server/api/locations.js13
-rw-r--r--server/api/permissions.js28
-rw-r--r--server/api/user.js31
4 files changed, 92 insertions, 0 deletions
diff --git a/server/api/clients.js b/server/api/clients.js
new file mode 100644
index 0000000..53aeb9d
--- /dev/null
+++ b/server/api/clients.js
@@ -0,0 +1,20 @@
+/* global __appdir */
+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
diff --git a/server/api/locations.js b/server/api/locations.js
new file mode 100644
index 0000000..c72ff93
--- /dev/null
+++ b/server/api/locations.js
@@ -0,0 +1,13 @@
+/* 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!');
+ }
+}
diff --git a/server/api/permissions.js b/server/api/permissions.js
new file mode 100644
index 0000000..bf24462
--- /dev/null
+++ b/server/api/permissions.js
@@ -0,0 +1,28 @@
+/* global __appdir */
+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 => {
+ 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
new file mode 100644
index 0000000..720a2bb
--- /dev/null
+++ b/server/api/user.js
@@ -0,0 +1,31 @@
+/* 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');
+
+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 => {
+ console.log("wasd");
+ //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);
+ });
+ }
+}