summaryrefslogtreecommitdiffstats
path: root/server/lib
diff options
context:
space:
mode:
authorUdo Walter2019-03-31 04:55:26 +0200
committerUdo Walter2019-03-31 04:55:26 +0200
commit5b59be3d0b2ae4f148a1d6c6f9781921c0e6042c (patch)
tree3cc0fbca5820c8fbbbaa84574ed4d3e23d455578 /server/lib
parent[webapp] small scrollbar style change (diff)
downloadbas-5b59be3d0b2ae4f148a1d6c6f9781921c0e6042c.tar.gz
bas-5b59be3d0b2ae4f148a1d6c6f9781921c0e6042c.tar.xz
bas-5b59be3d0b2ae4f148a1d6c6f9781921c0e6042c.zip
[server/groups] add more responses
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/httpresponse.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/server/lib/httpresponse.js b/server/lib/httpresponse.js
new file mode 100644
index 0000000..ff1010a
--- /dev/null
+++ b/server/lib/httpresponse.js
@@ -0,0 +1,13 @@
+const response = {}
+
+response.success = (res, action, type, id, data = {}) => res.status(200).send({ message: `Successfully ${action} ${type} ${id}.`, id, ...data })
+response.successBatch = (res, action, type, count, data = {}) => res.status(200).send({ message: `Successfully ${action} ${count} ${type + (count === 1 ? '' : 's')}.`, count, ...data })
+
+response.notFound = (res, id) => res.status(404).send({ error: 'NOT_FOUND', message: 'ID ' + id + ' does not exist.' })
+response.invalidId = (res, zeroAllowed) => res.status(400).send({ error: 'INVALID_ID', message: 'ID has to be an integer' + (zeroAllowed ? '' : ' greater than 0') + '.' })
+response.invalidBodyValue = (res, key, rule) => res.status(400).send({
+ error: 'BAD_REQUEST',
+ message: 'JSON body value for key "' + key + '" has to be ' + rule + '.'
+})
+
+module.exports = response \ No newline at end of file