how to make conditional validation using bodymen
tamilvjm opened this issue · 1 comments
tamilvjm commented
how to make conditional validation using bodymen? for example only validate if some flag is enabled.
Is there any such feature in it?
tguelcan commented
you can also import the simple validation like minlenght, required... also from the model schema of mongoose
For custom validation, you can use this way:
router.post(
'/',
body({
content: {
...content,
required: true,
minlength: 2,
validate: (value) => ({ valid: value === 'flag', message: 'Content value is not flag' }),
}
}),
create
)