]>
Commit | Line | Data |
---|---|---|
9f10b292 C |
1 | 'use strict' |
2 | ||
f0f5567b C |
3 | const checkErrors = require('./utils').checkErrors |
4 | const friends = require('../../lib/friends') | |
5 | const logger = require('../../helpers/logger') | |
9f10b292 | 6 | |
fc51fde0 | 7 | const validatorsPod = { |
9f10b292 C |
8 | makeFriends: makeFriends, |
9 | podsAdd: podsAdd | |
10 | } | |
11 | ||
12 | function makeFriends (req, res, next) { | |
1e2564d3 C |
13 | req.checkBody('urls', 'Should have an array of urls').isArray() |
14 | req.checkBody('urls', 'Should be an url').isEachUrl() | |
15 | ||
16 | logger.debug('Checking makeFriends parameters', { parameters: req.body }) | |
17 | ||
bc503c2a | 18 | friends.hasFriends(function (err, hasFriends) { |
9f10b292 C |
19 | if (err) { |
20 | logger.error('Cannot know if we have friends.', { error: err }) | |
21 | res.sendStatus(500) | |
22 | } | |
23 | ||
bc503c2a | 24 | if (hasFriends === true) { |
9f10b292 C |
25 | // We need to quit our friends before make new ones |
26 | res.sendStatus(409) | |
27 | } else { | |
1bfd1a92 | 28 | return next() |
9f10b292 C |
29 | } |
30 | }) | |
31 | } | |
32 | ||
33 | function podsAdd (req, res, next) { | |
528a9efa C |
34 | req.checkBody('url', 'Should have an url').notEmpty().isURL({ require_protocol: true }) |
35 | req.checkBody('publicKey', 'Should have a public key').notEmpty() | |
36 | ||
37 | // TODO: check we don't have it already | |
9f10b292 C |
38 | |
39 | logger.debug('Checking podsAdd parameters', { parameters: req.body }) | |
40 | ||
41 | checkErrors(req, res, next) | |
42 | } | |
43 | ||
44 | // --------------------------------------------------------------------------- | |
45 | ||
fc51fde0 | 46 | module.exports = validatorsPod |