UNPKG

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)

50 lines (47 loc) 1.1 kB
const { validateResult } = require('../../../middleware/utils') const validator = require('validator') const { check } = require('express-validator') /** * Validates update profile request */ const validateUpdateProfile = [ check('name') .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'), (req, res, next) => { validateResult(req, res, next) } ] module.exports = { validateUpdateProfile }