Advertisement
pionize

Untitled

Mar 8th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     function createAdv(req, res, next) {
  2.       req.assert('email').notEmpty().withMessage('Email address cannot be empty').isEmail().withMessage('Format email entered is not correct.').isUnique('email').withMessage('Email address is already in use by another user.');
  3.       req.assert('phone_number').notEmpty().withMessage('Phone Number cannot be empty.').matches(/^(\+62|0)[0-9][\d]{8,13}$/).withMessage('Invalid phone number format, must be preceded 0 or +62').isUnique('phone_number').withMessage('Phone Number is already in use by another user.');
  4.       req.assert('password').notEmpty().withMessage('Password cannot be empty.').isLength({
  5.         min: 6
  6.       }).withMessage('Password length of at least 6 characters.');
  7.       req.assert('brand').notEmpty().withMessage('Brand cannot be empty');
  8.       req.assert('photo').isBase64().withMessage('Photo format is not valid, it must be formatted base64');
  9.       req.assert('logo').isBase64().withMessage('Logo format is not valid, it must be formatted base64');
  10.  
  11.       if (req.user.type === constant.type.ADMIN) {
  12.         req.assert('full_name').notEmpty().withMessage('Full name cannot be empty.').matches(/[a-zA-Z ]{3,50}/).withMessage('Name at least 3 letters and should be in the form of the alphabet.');
  13.         //req.assert('photo').isBase64().withMessage('Photo format is not valid, it must be formatted base64'); -> pindah ke atas
  14.        
  15.         req.assert('group').notEmpty().withMessage('Group cannot be empty');
  16.         req.assert('brand').notEmpty().withMessage('Brand cannot be empty');
  17.         //req.assert('logo').isBase64().withMessage('Logo format is not valid, it must be formatted base64'); -> pindah ke atas
  18.         req.assert('color').notEmpty().withMessage('Color cannot be empty');
  19.         req.assert('address').notEmpty().withMessage('Address cannot be empty');
  20.         req.assert('state').notEmpty().withMessage('State cannot be empty');
  21.         req.assert('postal_code').notEmpty().matches(/[0-9]{5,6}/).withMessage('Postal code can only be a number');
  22.       }
  23.       req.asyncValidationErrors(true).catch((errors) => {
  24.         errors.message = 'Create Advertiser Failed';
  25.         errors.code = 400;
  26.         next(errors);
  27.       }).then(() => {
  28.         next();
  29.       });
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement