yield this.validateBody({ password: 'required', email_id: 'required' });
trying to validate the request body but when everything is in it, it still says Fields are required. everything is in it.
node 12.20.0
koa-validation 0.1.9
// Use koa-validate
'use strict';
var koa = require('koa');
var app = koa();
var router = require('koa-router')();
require('koa-validate')(app);
app.use(require('koa-body')({multipart:true , formidable:{keepExtensions:true}}));
app.use(router.routes()).use(router.allowedMethods());
router.post('/signup', function * () {
//optional() means this param may not in the params.
this.checkBody('name').optional().len(2, 20,"are you kidding me?");
this.checkBody('email').isEmail("your enter a bad email.");
this.checkBody('password').notEmpty().len(3, 20).md5();
//empty() mean this param can be a empty string.
this.checkBody('nick').optional().empty().len(3, 20);
//also we can get the sanitized value
var age = this.checkBody('age').toInt().value;
yield this.checkFile('icon').notEmpty().size(0,300*1024,'file too large').move("/static/icon/" , function*(file,context){
//resize image
});
if (this.errors) {
this.body = this.errors;
return;
}
});