}
function makeFriends (req, res, next) {
- req.checkBody('urls', 'Should have an array of urls').isArray()
- req.checkBody('urls', 'Should be an url').isEachUrl()
+ req.checkBody('urls', 'Should have an array of unique urls').isEachUniqueUrlValid()
logger.debug('Checking makeFriends parameters', { parameters: req.body })
- friends.hasFriends(function (err, hasFriends) {
- if (err) {
- logger.error('Cannot know if we have friends.', { error: err })
- res.sendStatus(500)
- }
-
- if (hasFriends === true) {
- // We need to quit our friends before make new ones
- res.sendStatus(409)
- } else {
- return next()
- }
+ checkErrors(req, res, function () {
+ friends.hasFriends(function (err, hasFriends) {
+ if (err) {
+ logger.error('Cannot know if we have friends.', { error: err })
+ res.sendStatus(500)
+ }
+
+ if (hasFriends === true) {
+ // We need to quit our friends before make new ones
+ res.sendStatus(409)
+ } else {
+ return next()
+ }
+ })
})
}