hey Chinedu - kept searching and found my answer! I am fired up - see below if anyone else is interested:
const { body, check, validationResult } = require('express-validator') const Team = require('../models/Team')
const teamValidationRules = () => {
return [ // is name present check('name'," a string 'name' is required.") .notEmpty().isString() .custom( async (value, {req}) => { const check = await Team.findOne({name: value})
if(check){ return Promise.reject('Name is already in use'); } }),
Great job, I just saw your comment, good to know you've been able to tackle it
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
hey Chinedu - kept searching and found my answer! I am fired up - see below if anyone else is interested:
const { body, check, validationResult } = require('express-validator')
const Team = require('../models/Team')
const teamValidationRules = () => {
return [
// is name present
check('name'," a string 'name' is required.")
.notEmpty().isString()
.custom(
async (value, {req}) => {
const check = await Team.findOne({name: value})
Great job, I just saw your comment, good to know you've been able to tackle it