summaryrefslogtreecommitdiffstats
path: root/server/api/groups.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/api/groups.js')
-rw-r--r--server/api/groups.js40
1 files changed, 40 insertions, 0 deletions
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()
+ }
+ }
+}