summaryrefslogtreecommitdiffstats
path: root/server/lib
diff options
context:
space:
mode:
authorUdo Walter2019-03-31 15:50:08 +0200
committerUdo Walter2019-03-31 15:50:08 +0200
commita8e6ec0d6496686399653375c00bc01a1ae262f7 (patch)
tree6a7ed1a87988c27e71927a907036460a6ec96098 /server/lib
parent[server/clients] add more responses (diff)
downloadbas-a8e6ec0d6496686399653375c00bc01a1ae262f7.tar.gz
bas-a8e6ec0d6496686399653375c00bc01a1ae262f7.tar.xz
bas-a8e6ec0d6496686399653375c00bc01a1ae262f7.zip
[server/ipxeconfigs] add more responses
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/httpresponse.js10
1 files changed, 7 insertions, 3 deletions
diff --git a/server/lib/httpresponse.js b/server/lib/httpresponse.js
index ff1010a..6a5d552 100644
--- a/server/lib/httpresponse.js
+++ b/server/lib/httpresponse.js
@@ -1,13 +1,17 @@
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.successBatch = (res, action, type, count, data = {}) => {
+ if (Array.isArray(type) && type.length === 2) type = count === 1 ? type[0] : type[1]
+ else if (typeof type === 'string' && count !== 1) type += 's'
+ return res.status(200).send({ message: `Successfully ${action} ${count} ${type}.`, 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 + '.'
+ error: 'BAD_REQUEST',
+ message: 'JSON body value for key "' + key + '" has to be ' + rule + '.'
})
module.exports = response \ No newline at end of file