summaryrefslogtreecommitdiffstats
path: root/server/lib/httpresponse.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/httpresponse.js')
-rw-r--r--server/lib/httpresponse.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/server/lib/httpresponse.js b/server/lib/httpresponse.js
index 29399b2..4ef6ab1 100644
--- a/server/lib/httpresponse.js
+++ b/server/lib/httpresponse.js
@@ -1,7 +1,11 @@
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') + '.' })