res.respond: allow for thrid parameter (message), refactor shared ops responses and adapt tests

This commit is contained in:
Matteo Pagliazzi
2016-04-21 00:52:03 +02:00
parent 9e3d8ba4ac
commit 6568fcfd5e
81 changed files with 419 additions and 465 deletions

View File

@@ -7,8 +7,7 @@ import {
import _ from 'lodash';
module.exports = function addWebhook (user, req = {}) {
let wh;
wh = user.preferences.webhooks;
let wh = user.preferences.webhooks;
if (!validator.isURL(_.get(req, 'body.url'))) throw new BadRequest(i18n.t('invalidUrl', req.language));
if (!validator.isBoolean(_.get(req, 'body.enabled'))) throw new BadRequest(i18n.t('invalidEnabled', req.language));
@@ -18,9 +17,11 @@ module.exports = function addWebhook (user, req = {}) {
if (req.v2 === true) {
return user.preferences.webhooks;
} else {
return refPush(wh, {
url: req.body.url,
enabled: req.body.enabled,
});
return [
refPush(wh, {
url: req.body.url,
enabled: req.body.enabled,
}),
];
}
};