summaryrefslogtreecommitdiffstats
path: root/server/api/clients.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/clients.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/clients.js')
-rw-r--r--server/api/clients.js15
1 files changed, 9 insertions, 6 deletions
diff --git a/server/api/clients.js b/server/api/clients.js
index 4f7ce1d..06fa780 100644
--- a/server/api/clients.js
+++ b/server/api/clients.js
@@ -27,7 +27,8 @@ module.exports.get = {
// get name, description, ip, mac and uuid of a client (by id)
getClient: function (req, res) {
db.client.findOne({ where: { id: req.query.id }, include: ['groups'] }).then(client => {
- res.send(client)
+ if (client) res.send(client)
+ else res.status(404).end()
})
}
}
@@ -39,10 +40,12 @@ module.exports.post = {
const id = req.body.id > 0 ? req.body.id : null
if (id) {
db.client.findOne({ where: { id } }).then(client => {
- var promises = []
- if (req.body.info) promises.push([client.update(req.body.info)])
- if (req.body.groupIds) promises.push(client.setGroups(req.body.groupIds))
- Promise.all(promises).then(() => { res.send({ id }) })
+ if (client) {
+ var promises = []
+ if (req.body.info) promises.push([client.update(req.body.info)])
+ if (req.body.groupIds) promises.push(client.setGroups(req.body.groupIds))
+ Promise.all(promises).then(() => { res.send({ id }) })
+ } else { res.status(404).end() }
})
} else {
db.client.create(req.body.info).then(client => {
@@ -53,6 +56,6 @@ module.exports.post = {
// delete clients
delete: function (req, res) {
- db.client.destroy({ where: { id: req.body.ids } }).then(() => { res.end() })
+ db.client.destroy({ where: { id: req.body.ids } }).then(count => { res.end(count) })
}
}