Skip to content

Commit

Permalink
modified example
Browse files Browse the repository at this point in the history
  • Loading branch information
RocksonZeta committed Dec 15, 2014
1 parent 4b990d3 commit 53dfc78
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ app.post('/signup', function * () {
this.body = this.errors;
return;
}
this.body = this.body;
this.body = this.request.body;
});
app.get('/users', function * () {
this.checkQuery('department').empty().in(["sale","finance"], "not support this department!").len(3, 20);
Expand Down
10 changes: 10 additions & 0 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ module.exports = function() {
return function * (next) {
debug('init koa-validate');
this.checkBody = function(key) {
if('undefined' == typeof this.request.body) {
if(!this.errors){
this.errors = ['no body to check'];
}
}
var body = this.request.body.fields || this.request.body; // koa-body fileds
return new Validator(this, key, body[key], key in body , body );
};
Expand All @@ -20,6 +25,11 @@ module.exports = function() {
return new Validator(this, key, this.params[key], key in this.params,this.params);
};
this.checkFile = function(key , deleteOnCheckFailed) {
if('undefined' == typeof this.request.body || 'undefined' == typeof this.request.body.files ) {
if(!this.errors){
this.errors = ['no body to check'];
}
}
deleteOnCheckFailed = ('undefined' == typeof deleteOnCheckFailed?true :false);
var files = this.request.body.files;
return new FileValidator(this, key ,files&&files[key],!!(files&&files[key]) , this.request.body , deleteOnCheckFailed);
Expand Down

0 comments on commit 53dfc78

Please sign in to comment.