From 028c9aaa8651862b2bd495c527d30845d1fb1f50 Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Thu, 2 Aug 2018 16:13:05 +0000 Subject: [groups] add dialog to delete, remove and add groups/clients --- server/api/groups.js | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'server/api/groups.js') diff --git a/server/api/groups.js b/server/api/groups.js index ece6b43..a41666a 100644 --- a/server/api/groups.js +++ b/server/api/groups.js @@ -39,7 +39,7 @@ module.exports.post = { save: function (req, res) { const id = req.body.id > 0 ? req.body.id : null if (id) { - db.group.findOne({ where: { id: id } }).then(group => { + db.group.findOne({ where: { id } }).then(group => { var promises = [] if (req.body.info) promises.push([group.update(req.body.info)]) if (req.body.parentIds) promises.push(group.setParents(req.body.parentIds)) @@ -55,5 +55,45 @@ module.exports.post = { // delete groups delete: function (req, res) { db.group.destroy({ where: { id: req.body.ids } }).then(() => { res.end() }) + }, + + // remove subgroups from a group + removeSubgroups: function (req, res) { + const id = req.body.id > 0 ? req.body.id : null + if (id) { + db.group.findOne({ where: { id } }).then(group => { + group.removeSubgroups(req.body.ids).then(() => { res.end() }) + }) + } else { res.status(404).end() } + }, + + // remove clients from a group + removeClients: function (req, res) { + const id = req.body.id > 0 ? req.body.id : null + if (id) { + db.group.findOne({ where: { id } }).then(group => { + group.removeClients(req.body.ids).then(() => { res.end() }) + }) + } else { res.status(404).end() } + }, + + // add subgroups to a group + addSubgroups: function (req, res) { + const id = req.body.id > 0 ? req.body.id : null + if (id) { + db.group.findOne({ where: { id } }).then(group => { + group.addSubgroups(req.body.ids).then(() => { res.end() }) + }) + } else { res.status(404).end() } + }, + + // add clients to a group + addClients: function (req, res) { + const id = req.body.id > 0 ? req.body.id : null + if (id) { + db.group.findOne({ where: { id } }).then(group => { + group.addClients(req.body.ids).then(() => { res.end() }) + }) + } else { res.status(404).end() } } } -- cgit v1.2.3-55-g7522