module.exports = (() => {
  var feedback = (req, cb) => {
    var errors = req.validationErrors();
    if (errors) { // Display errors to user
      var error = {
        success: false,
        message: 'Params Validation Failed!',
        errors: errors
      };
      cb(error);
    } else cb();
  };

  var validateAuthParams = (req, cb) => {
    // validate request body fields.
    req.checkBody('login', 'username or email is required to gain access')
      .notEmpty();
    req.checkBody('password', 'password field cannot be empty.').notEmpty();
    return feedback(req, cb);
  };

  function validateUserDetails(req, cb) {
    // validate request body fields.
    req.checkBody('username', 'username is required')
      .len(4, 20).withMessage('username should be between 6 to 30 characters')
      .notEmpty();
    req.checkBody('lastname', 'lastname is required')
      .isAlpha().withMessage('lastname can only contain alphabets')
      .len(1, 50).withMessage('lastname should be between 6 to 50 characters')
      .notEmpty();
    req.checkBody('firstname', 'firstname is required')
      .isAlpha().withMessage('firstname can only contain alphabets')
      .len(1, 50).withMessage('firstname should be between 6 to 50 characters')
      .notEmpty();
    req.checkBody('email', 'Invalid Email. Please provide a valid email')
      .notEmpty().withMessage('email is required')
      .isEmail();
    req.checkBody('password', 'password is required')
      .len(6, 20).withMessage('password should be between 6 to 20 characters')
      .notEmpty();
    req.checkBody('role', 'role is required')
      .len(3, 20).withMessage('role should be between 6 to 50 characters')
      .notEmpty();
    return feedback(req, cb);
  }

  function validatePaginationParams(req, cb) {
    if (req.query.hasOwnProperty('page'))
      req.checkQuery('page', 'Page number must be an interger').isInt();
    if (req.query.hasOwnProperty('limit'))
      req.checkQuery('limit', 'limit must be an interger').isInt();
    return feedback(req, cb);
  }

  function validateId(req, cb) {
    req.checkParams('id', 'userId is required to fetch a user')
      .len(24).withMessage('Invalid Id')
      .notEmpty();
    return feedback(req, cb);
  }

  function validateDocDetails(req, cb) {
    req.checkBody('title', 'Document title is required')
      .len(3, 50)
      .withMessage('Document title can only be between 3 to 50 characters.')
      .notEmpty();
    req.checkBody('content', 'Document content is required')
      .len(0, 2000)
      .withMessage('Document content can only contain 1000 characters.')
      .notEmpty();
    req.checkBody('roles', 'Atleast a role must be specified.')
      .notEmpty();
    return feedback(req, cb);
  }

  var validateRoleTitle = (req, cb) => {
    req.checkBody('title', 'Role title is required to create new role.')
      .len(2, 50).withMessage('Role title can only be between 3 to 50 characters.')
      .notEmpty();
    return feedback(req, cb);
  };

  return {
    validateAuthParams: validateAuthParams,
    validateUserDetails: validateUserDetails,
    validatePaginationParams: validatePaginationParams,
    validateId: validateId,
    validateDocDetails: validateDocDetails,
    validateRoleTitle: validateRoleTitle
  };
})();

@@ -299,17 +299,13 @@
 %0A  %7D
-;
+,
 %0A%0A  
-var 
 vali
@@ -581,22 +581,13 @@
 %0A  %7D
-;
+,
 %0A%0A  
-function 
 vali
@@ -597,24 +597,27 @@
 eUserDetails
+ = 
 (req, cb) %7B%0A
@@ -609,24 +609,27 @@
  = (req, cb)
+ =%3E
  %7B%0A    // va
@@ -688,32 +688,8 @@
 ame'
-, 'username is required'
 )%0A  
@@ -764,34 +764,16 @@
 acters')
-%0A      .notEmpty()
 ;%0A    re
@@ -798,32 +798,8 @@
 ame'
-, 'lastname is required'
 )%0A  
@@ -942,34 +942,16 @@
 acters')
-%0A      .notEmpty()
 ;%0A    re
@@ -977,33 +977,8 @@
 ame'
-, 'firstname is required'
 )%0A  
@@ -1123,34 +1123,16 @@
 acters')
-%0A      .notEmpty()
 ;%0A    re
@@ -1448,28 +1448,8 @@
 ole'
-, 'role is required'
 )%0A  
@@ -1520,34 +1520,16 @@
 acters')
-%0A      .notEmpty()
 ;%0A    re
@@ -1551,37 +1551,29 @@
 eq, cb);%0A  %7D
+,
 %0A%0A  
-function 
 validatePagi
@@ -1584,16 +1584,19 @@
 onParams
+ = 
 (req, cb
@@ -1592,24 +1592,27 @@
  = (req, cb)
+ =%3E
  %7B%0A    if (r
@@ -1857,37 +1857,29 @@
 eq, cb);%0A  %7D
+,
 %0A%0A  
-function 
 validateId(r
@@ -1876,16 +1876,19 @@
 lidateId
+ = 
 (req, cb
@@ -1880,32 +1880,35 @@
 teId = (req, cb)
+ =%3E
  %7B%0A    req.check
@@ -1971,16 +1971,210 @@
  .len(24
+, 24).withMessage('Invalid Id')%0A      .notEmpty();%0A    return feedback(req, cb);%0A  %7D,%0A%0A  validatePubId = (req, cb) =%3E %7B%0A    req.checkParams('id', 'Image public id is required')%0A      .len(20, 20
 ).withMe
@@ -2249,21 +2249,13 @@
 %0A  %7D
+,
 %0A%0A  
-function 
 vali
@@ -2268,16 +2268,19 @@
 cDetails
+ = 
 (req, cb
@@ -2280,16 +2280,19 @@
 req, cb)
+ =%3E
  %7B%0A    r
@@ -2750,16 +2750,13 @@
 %0A  %7D
+,
 %0A%0A  
-var 
 vali
@@ -2872,24 +2872,31 @@
  .len(2, 50)
+%0A      
 .withMessage
@@ -3190,16 +3190,50 @@
 dateId,%0A
+    validatePubId: validatePubId,%0A
     vali

Correct indentation Remove checks on a couple of fields