summaryrefslogtreecommitdiffstats
path: root/server/api/groups.js
diff options
context:
space:
mode:
authorUdo Walter2018-08-01 22:17:33 +0200
committerUdo Walter2018-08-01 22:17:33 +0200
commitfaf1188d03e1302dd615a118bce73dd6197be8f1 (patch)
tree207d484a6d68f3d77bc49815ea92c13f4da057c3 /server/api/groups.js
parent[server/idoit] iDoIT api call returns now the object itself and the childs. (diff)
downloadbas-faf1188d03e1302dd615a118bce73dd6197be8f1.tar.gz
bas-faf1188d03e1302dd615a118bce73dd6197be8f1.tar.xz
bas-faf1188d03e1302dd615a118bce73dd6197be8f1.zip
[groups] add edit functionality to group infos
Diffstat (limited to 'server/api/groups.js')
-rw-r--r--server/api/groups.js42
1 files changed, 21 insertions, 21 deletions
diff --git a/server/api/groups.js b/server/api/groups.js
index fa2c1ca..5916585 100644
--- a/server/api/groups.js
+++ b/server/api/groups.js
@@ -4,42 +4,42 @@ var db = require(path.join(__appdir, 'lib', 'sequelize'))
// GET Requests
module.exports.get = {
+ // get a list containing id and name of all groups
getList: function (req, res) {
db.group.findAll({ attributes: ['id', 'name'] }).then(list => {
res.send(list)
})
},
- 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)
- })
+ // get all groups that have no parents
+ getTopLevel: function (req, res) {
+ db.group.findAll({ where: { '$parents.id$': null }, include: ['parents'] }).then(groups => {
+ res.send(groups)
})
},
- 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)
- })
- },
-
- 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)
+ // get name, description, parents, subgroups and clients of a group (by id)
+ getGroup: function (req, res) {
+ db.group.findOne({ where: { id: req.query.id }, include: ['parents', 'subgroups', 'clients'] }).then(group => {
+ res.send(group)
})
}
}
// POST Requests
module.exports.post = {
- update: function (req, res) {
+ // create group or update information of a group (returns id)
+ saveInfo: 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()
+ if (id) {
+ db.group.findOne({ where: { id: id } }).then(group => {
+ Promise.all([
+ group.update({ name: req.body.name, description: req.body.description }),
+ group.setParents(req.body.parentIds)
+ ]).then(() => { res.send({id}) })
+ })
+ } else {
+ res.end()
+ }
}
}