aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/reqValidators/pods.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/reqValidators/pods.js')
-rw-r--r--server/middlewares/reqValidators/pods.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/server/middlewares/reqValidators/pods.js b/server/middlewares/reqValidators/pods.js
new file mode 100644
index 000000000..ef09d51cf
--- /dev/null
+++ b/server/middlewares/reqValidators/pods.js
@@ -0,0 +1,39 @@
1'use strict'
2
3var checkErrors = require('./utils').checkErrors
4var friends = require('../../lib/friends')
5var logger = require('../../helpers/logger')
6
7var reqValidatorsPod = {
8 makeFriends: makeFriends,
9 podsAdd: podsAdd
10}
11
12function makeFriends (req, res, next) {
13 friends.hasFriends(function (err, has_friends) {
14 if (err) {
15 logger.error('Cannot know if we have friends.', { error: err })
16 res.sendStatus(500)
17 }
18
19 if (has_friends === true) {
20 // We need to quit our friends before make new ones
21 res.sendStatus(409)
22 } else {
23 return next()
24 }
25 })
26}
27
28function podsAdd (req, res, next) {
29 req.checkBody('data.url', 'Should have an url').notEmpty().isURL({ require_protocol: true })
30 req.checkBody('data.publicKey', 'Should have a public key').notEmpty()
31
32 logger.debug('Checking podsAdd parameters', { parameters: req.body })
33
34 checkErrors(req, res, next)
35}
36
37// ---------------------------------------------------------------------------
38
39module.exports = reqValidatorsPod