diff options
Diffstat (limited to 'server/middlewares/validators/pods.js')
-rw-r--r-- | server/middlewares/validators/pods.js | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/server/middlewares/validators/pods.js b/server/middlewares/validators/pods.js index fda2e865f..fd3d1e2f2 100644 --- a/server/middlewares/validators/pods.js +++ b/server/middlewares/validators/pods.js | |||
@@ -5,23 +5,29 @@ const friends = require('../../lib/friends') | |||
5 | const logger = require('../../helpers/logger') | 5 | const logger = require('../../helpers/logger') |
6 | 6 | ||
7 | const validatorsPod = { | 7 | const validatorsPod = { |
8 | makeFriends: makeFriends, | 8 | makeFriends, |
9 | podsAdd: podsAdd | 9 | podsAdd |
10 | } | 10 | } |
11 | 11 | ||
12 | function makeFriends (req, res, next) { | 12 | function makeFriends (req, res, next) { |
13 | friends.hasFriends(function (err, hasFriends) { | 13 | req.checkBody('urls', 'Should have an array of unique urls').isEachUniqueUrlValid() |
14 | if (err) { | 14 | |
15 | logger.error('Cannot know if we have friends.', { error: err }) | 15 | logger.debug('Checking makeFriends parameters', { parameters: req.body }) |
16 | res.sendStatus(500) | 16 | |
17 | } | 17 | checkErrors(req, res, function () { |
18 | 18 | friends.hasFriends(function (err, hasFriends) { | |
19 | if (hasFriends === true) { | 19 | if (err) { |
20 | // We need to quit our friends before make new ones | 20 | logger.error('Cannot know if we have friends.', { error: err }) |
21 | res.sendStatus(409) | 21 | res.sendStatus(500) |
22 | } else { | 22 | } |
23 | return next() | 23 | |
24 | } | 24 | if (hasFriends === true) { |
25 | // We need to quit our friends before make new ones | ||
26 | res.sendStatus(409) | ||
27 | } else { | ||
28 | return next() | ||
29 | } | ||
30 | }) | ||
25 | }) | 31 | }) |
26 | } | 32 | } |
27 | 33 | ||