我正在研究快速验证器,我正在尝试对尸体进行评估:
const lessonSchema = {
lessonName: {
in: ['body'],
exists: {
checkNull: true,
checkFalsy: true,
errorMessage: 'lessonName is required'
},
isEmpty: { negated: true, errorMessage: 'lessonName is required' }
},
assistantTeacherId: {
in: ['body'],
custom: {
options: (value, { req }) => {
if (value === '') {
req.body.assistantTeacherId = 0;
}
if (req.body.teacherId && value === req.body.teacherId) {
body.assistantTeacherId = 0;
}
return true;
}
}
}
};
const validateLesson = checkSchema(lessonSchema);
这是尸体:
{“ lessonName”:null,“ assistantTeacherId”:1,}
对于关键assitantTeacherId而言,validate效果很好,但对于lessonName则无效。我做了很多研究,但仍然找不到解决方法。