node-express-mongodb-jwt-rest-api-skeleton
Version:
Node.js express.js MongoDB JWT REST API - This is a basic API REST skeleton written on JavaScript using async/await. Great for building a starter web API for your front-end (Android, iOS, Vue, react, angular, or anything that can consume an API)
68 lines (65 loc) • 1.43 kB
JavaScript
const { validateResult } = require('../../../middleware/utils')
const validator = require('validator')
const { check } = require('express-validator')
/**
* Validates update item request
*/
const validateUpdateUser = [
check('name')
.exists()
.withMessage('MISSING')
.not()
.isEmpty()
.withMessage('IS_EMPTY'),
check('email')
.exists()
.withMessage('MISSING')
.not()
.isEmpty()
.withMessage('IS_EMPTY'),
check('role')
.exists()
.withMessage('MISSING')
.not()
.isEmpty()
.withMessage('IS_EMPTY'),
check('phone')
.exists()
.withMessage('MISSING')
.not()
.isEmpty()
.withMessage('IS_EMPTY')
.trim(),
check('city')
.exists()
.withMessage('MISSING')
.not()
.isEmpty()
.withMessage('IS_EMPTY')
.trim(),
check('country')
.exists()
.withMessage('MISSING')
.not()
.isEmpty()
.withMessage('IS_EMPTY')
.trim(),
check('urlTwitter')
.optional()
.custom((v) => (v === '' ? true : validator.isURL(v)))
.withMessage('NOT_A_VALID_URL'),
check('urlGitHub')
.optional()
.custom((v) => (v === '' ? true : validator.isURL(v)))
.withMessage('NOT_A_VALID_URL'),
check('id')
.exists()
.withMessage('MISSING')
.not()
.isEmpty()
.withMessage('IS_EMPTY'),
(req, res, next) => {
validateResult(req, res, next)
}
]
module.exports = { validateUpdateUser }