summaryrefslogtreecommitdiffstats
path: root/server/api/groups.js
diff options
context:
space:
mode:
authorUdo Walter2018-07-30 01:31:08 +0200
committerUdo Walter2018-07-30 01:31:08 +0200
commitf6cadb25e42e6568098f2962fa9b302cfbf074c5 (patch)
tree4dd205c43603b22d00b2b51a162922643014e436 /server/api/groups.js
parent[store/global] simplified settings loading (diff)
downloadbas-f6cadb25e42e6568098f2962fa9b302cfbf074c5.tar.gz
bas-f6cadb25e42e6568098f2962fa9b302cfbf074c5.tar.xz
bas-f6cadb25e42e6568098f2962fa9b302cfbf074c5.zip
[server/router] changed api routing from query keyword to url parameter for group and client api (todo: the rest)
Diffstat (limited to 'server/api/groups.js')
-rw-r--r--server/api/groups.js62
1 files changed, 31 insertions, 31 deletions
diff --git a/server/api/groups.js b/server/api/groups.js
index 8158d1c..ff29799 100644
--- a/server/api/groups.js
+++ b/server/api/groups.js
@@ -3,40 +3,40 @@ 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 'getParents':
- db.group.findOne({ where: { id: req.query.id }, include: ['parents']}).then(group => {
- group.getParents().then(parents => {
- res.send(parents.map(x => ({ id: x.id, name: x.name })))
- })
- })
- 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)
+ get: {
+
+ getParents: function (req, res) {
+ const id = req.query.id > 0 ? req.query.id : null
+ db.group.findOne({ where: { id: id }, include: ['parents'] }).then(group => {
+ group.getParents().then(parents => {
+ res.send(parents.map(x => ({ id: x.id, name: x.name })))
})
- break
- default:
- res.end()
+ })
+ },
+
+ getSubGroups: function (req, res) {
+ const id = req.query.id > 0 ? req.query.id : null
+ db.group.findAll({ where: { '$parents.id$': id }, include: ['parents'] }).then(result => {
+ res.send(result)
+ })
+ },
+
+ getClients: function (req, res) {
+ const id = req.query.id > 0 ? req.query.id : null
+ db.client.findAll({ where: { '$groups.id$': id }, include: ['groups'] }).then(result => {
+ res.send(result)
+ })
}
+
},
- post: function (req, res) {
- var id = req.body.id > 0 ? req.body.id : null
- switch (req.body.action) {
- case 'update':
- if (!id) res.end()
- db.group.update({ name: req.body.name }, { where: { id: id } })
- res.end()
- break
- default:
- res.end()
+ post: {
+
+ update: function (req, res) {
+ const id = req.body.id > 0 ? req.body.id : null
+ if (!id) res.end()
+ db.group.update({ name: req.body.name }, { where: { id: id } })
+ res.end()
}
+
}
}