summaryrefslogtreecommitdiffstats
path: root/server/api
diff options
context:
space:
mode:
authorUdo Walter2018-07-19 05:58:05 +0200
committerUdo Walter2018-07-19 05:58:05 +0200
commit039be437233b3443f8ab0b93d6f34929534ba670 (patch)
treeb6b20518172372a5d52693fdf7b7a1c0e60c96af /server/api
parent[webapp/dashboard] added devMode (diff)
downloadbas-039be437233b3443f8ab0b93d6f34929534ba670.tar.gz
bas-039be437233b3443f8ab0b93d6f34929534ba670.tar.xz
bas-039be437233b3443f8ab0b93d6f34929534ba670.zip
[server/groups][webapp/groups] added first version of the groups module
Diffstat (limited to 'server/api')
-rw-r--r--server/api/clients.js18
-rw-r--r--server/api/groups.js40
-rw-r--r--server/api/locations.js13
3 files changed, 49 insertions, 22 deletions
diff --git a/server/api/clients.js b/server/api/clients.js
index f7fe455..aeb4673 100644
--- a/server/api/clients.js
+++ b/server/api/clients.js
@@ -4,15 +4,15 @@ 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()
+ switch (req.query.action) {
+ case 'getInfo':
+ db.client.findOne({ where: { id: req.query.id }}).then(client => {
+ res.send(client)
+ })
+ break
+ default:
+ res.end()
+ }
},
post: function (req, res) {
diff --git a/server/api/groups.js b/server/api/groups.js
new file mode 100644
index 0000000..2d1182b
--- /dev/null
+++ b/server/api/groups.js
@@ -0,0 +1,40 @@
+/* global __appdir */
+var path = require('path')
+var db = require(path.join(__appdir, 'lib', 'sequelize'))
+
+module.exports = {
+ get: function (req, res) {
+ var id = req.query.id > 0 ? req.query.id : null
+ switch (req.query.action) {
+ case 'getInfo':
+ db.group.findOne({ where: { id: req.query.id }}).then(group => {
+ res.send(group)
+ })
+ break
+ case 'getSubGroups':
+ db.group.findAll({ where: { '$parents.id$': id }, include: ['parents'] }).then(result => {
+ res.send(result)
+ })
+ break
+ case 'getClients':
+ db.client.findAll({ where: { '$groups.id$': id }, include: ['groups'] }).then(result => {
+ res.send(result)
+ })
+ break
+ default:
+ res.end()
+ }
+ },
+ post: function (req, res) {
+ var id = req.body.id > 0 ? req.body.id : null
+ switch (req.body.action) {
+ case 'setInfo':
+ if (!id) res.end()
+ db.group.update({ name: req.body.name }, { where: { id: id } })
+ res.end()
+ break
+ default:
+ res.end()
+ }
+ }
+}
diff --git a/server/api/locations.js b/server/api/locations.js
deleted file mode 100644
index 7595837..0000000
--- a/server/api/locations.js
+++ /dev/null
@@ -1,13 +0,0 @@
-// /* 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!')
- }
-}