Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function createAdv(req, res, next) {
- 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.');
- 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.');
- req.assert('password').notEmpty().withMessage('Password cannot be empty.').isLength({
- min: 6
- }).withMessage('Password length of at least 6 characters.');
- req.assert('brand').notEmpty().withMessage('Brand cannot be empty');
- req.assert('photo').isBase64().withMessage('Photo format is not valid, it must be formatted base64');
- req.assert('logo').isBase64().withMessage('Logo format is not valid, it must be formatted base64');
- if (req.user.type === constant.type.ADMIN) {
- 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.');
- //req.assert('photo').isBase64().withMessage('Photo format is not valid, it must be formatted base64'); -> pindah ke atas
- req.assert('group').notEmpty().withMessage('Group cannot be empty');
- req.assert('brand').notEmpty().withMessage('Brand cannot be empty');
- //req.assert('logo').isBase64().withMessage('Logo format is not valid, it must be formatted base64'); -> pindah ke atas
- req.assert('color').notEmpty().withMessage('Color cannot be empty');
- req.assert('address').notEmpty().withMessage('Address cannot be empty');
- req.assert('state').notEmpty().withMessage('State cannot be empty');
- req.assert('postal_code').notEmpty().matches(/[0-9]{5,6}/).withMessage('Postal code can only be a number');
- }
- req.asyncValidationErrors(true).catch((errors) => {
- errors.message = 'Create Advertiser Failed';
- errors.code = 400;
- next(errors);
- }).then(() => {
- next();
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement