summaryrefslogtreecommitdiffstats
path: root/server/api/groups.js
diff options
context:
space:
mode:
authorUdo Walter2018-08-04 04:25:05 +0200
committerUdo Walter2018-08-04 04:25:05 +0200
commit8270b5c6b35302611eedde263f09535c66bee626 (patch)
treec411e275df0742610549d9600fb6fb719fa36584 /server/api/groups.js
parent[webapp/groups] add routes; groups and clients can now be accessed directly u... (diff)
downloadbas-8270b5c6b35302611eedde263f09535c66bee626.tar.gz
bas-8270b5c6b35302611eedde263f09535c66bee626.tar.xz
bas-8270b5c6b35302611eedde263f09535c66bee626.zip
[server/groups] add 404 status code if group / client id not found
Diffstat (limited to 'server/api/groups.js')
-rw-r--r--server/api/groups.js51
1 files changed, 25 insertions, 26 deletions
diff --git a/server/api/groups.js b/server/api/groups.js
index a41666a..526f3ee 100644
--- a/server/api/groups.js
+++ b/server/api/groups.js
@@ -28,7 +28,8 @@ module.exports.get = {
// 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)
+ if (group) res.send(group)
+ else res.status(404).end()
})
}
}
@@ -40,10 +41,12 @@ module.exports.post = {
const id = req.body.id > 0 ? req.body.id : null
if (id) {
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))
- Promise.all(promises).then(() => { res.send({id}) })
+ if (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))
+ Promise.all(promises).then(() => { res.send({id}) })
+ } else { res.status(404).end() }
})
} else {
db.group.create(req.body.info).then(group => {
@@ -54,46 +57,42 @@ module.exports.post = {
// delete groups
delete: function (req, res) {
- db.group.destroy({ where: { id: req.body.ids } }).then(() => { res.end() })
+ db.group.destroy({ where: { id: req.body.ids } }).then(count => { res.end(count) })
},
// 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 => {
+ db.group.findOne({ where: { id: req.body.id } }).then(group => {
+ if (group) {
group.removeSubgroups(req.body.ids).then(() => { res.end() })
- })
- } else { res.status(404).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 => {
+ db.group.findOne({ where: { id: req.body.id } }).then(group => {
+ if (group) {
group.removeClients(req.body.ids).then(() => { res.end() })
- })
- } else { res.status(404).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 => {
+ db.group.findOne({ where: { id: req.body.id } }).then(group => {
+ if (group) {
group.addSubgroups(req.body.ids).then(() => { res.end() })
- })
- } else { res.status(404).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 => {
+ db.group.findOne({ where: { id: req.body.id } }).then(group => {
+ if (group) {
group.addClients(req.body.ids).then(() => { res.end() })
- })
- } else { res.status(404).end() }
+ } else { res.status(404).end() }
+ })
}
}