summaryrefslogtreecommitdiffstats
path: root/server/api/groups.js
diff options
context:
space:
mode:
authorUdo Walter2018-07-31 04:20:37 +0200
committerUdo Walter2018-07-31 04:20:37 +0200
commitcb7711cc9f76fe4211538bad74de68c57cd07e83 (patch)
tree633568bcbc8737e97eb0e99eaefbf846422e6147 /server/api/groups.js
parent[webapp/external-backends] Dialog polishing. Thx Udo for fixing the scroll co... (diff)
downloadbas-cb7711cc9f76fe4211538bad74de68c57cd07e83.tar.gz
bas-cb7711cc9f76fe4211538bad74de68c57cd07e83.tar.xz
bas-cb7711cc9f76fe4211538bad74de68c57cd07e83.zip
[groups] add edit form for groups; add description to groups and clients
Diffstat (limited to 'server/api/groups.js')
-rw-r--r--server/api/groups.js63
1 files changed, 33 insertions, 30 deletions
diff --git a/server/api/groups.js b/server/api/groups.js
index ff29799..fa2c1ca 100644
--- a/server/api/groups.js
+++ b/server/api/groups.js
@@ -2,41 +2,44 @@
var path = require('path')
var db = require(path.join(__appdir, 'lib', 'sequelize'))
-module.exports = {
- 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 })))
- })
- })
- },
-
- 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)
- })
- },
+// GET Requests
+module.exports.get = {
+ getList: function (req, res) {
+ db.group.findAll({ attributes: ['id', 'name'] }).then(list => {
+ res.send(list)
+ })
+ },
- 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)
+ 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)
})
- }
+ })
+ },
+ getSubGroups: function (req, res) {
+ const id = req.query.id > 0 ? req.query.id : null
+ db.group.findAll({ where: { '$parents.id$': id }, include: ['parents'] }).then(subgroups => {
+ res.send(subgroups)
+ })
},
- 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()
- }
+ getClients: function (req, res) {
+ const id = req.query.id > 0 ? req.query.id : null
+ db.client.findAll({ where: { '$groups.id$': id }, include: ['groups'] }).then(clients => {
+ res.send(clients)
+ })
+ }
+}
+// POST Requests
+module.exports.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()
}
}