Skip to content

Commit

Permalink
change context attach body to .fleek.validate
Browse files Browse the repository at this point in the history
  • Loading branch information
Lan Nguyen committed Sep 29, 2015
1 parent 8ea5035 commit 3002113
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@ exports.templateTracer = function (routeSet) {

// return a function to get the template
return function (ctx) {
ctx.routeConfig = ctx.routeConfig || {};
ctx.fleek.routeConfig = ctx.fleek.routeConfig || {};

methodPaths = methodMap[ctx.request.method.toLowerCase()];
_.each(methodPaths, function (compiledTemplate) {
if (compiledTemplate.regexp.test(ctx.request.path)) {
ctx.routeConfig.path = compiledTemplate.path
ctx.fleek.routeConfig.path = compiledTemplate.path
return false; // we're done here
}
});

return ctx.routeConfig.path;
return ctx.fleek.routeConfig.path;
}
}

Expand Down
21 changes: 12 additions & 9 deletions lib/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ var validator = function (app, config) {
var tracePath = helpers.templateTracer(routeValidationMap);

var valMiddleware = function *(next) {
this.routeConfig = this.routeConfig || {};
this.validated = false;
this.fleek = this.fleek || {};
this.fleek.routeConfig = this.fleek.routeConfig || {};
this.fleek.validated = false;

validate.isErr = validate.isError = validate.isValError = validate.isValidationError = validate.isValErr = helpers.isValidationError;
this.validate = validate;

this.fleek.validate = validate;
var method = this.request.method.toLowerCase();
var path = null;

// get the path form the route config
if (this.routeConfig.path) {
path = this.routeConfig.path
if (this.fleek.routeConfig.path) {
path = this.fleek.routeConfig.path

// if the route config doesnt exist, trace it
} else {
Expand All @@ -60,13 +63,13 @@ var validator = function (app, config) {
// get the parameters array fro the route
var parameters = (routeValidationMap[path] || {})[method];
if (_.isArray(parameters)) {
this.validated = true;
var result = this.validate.ctx(this, parameters);
this.fleek.validated = true;
var result = this.fleek.validate.ctx(this, parameters);

if (this.validate.isErr(result)) {
if (this.fleek.validate.isErr(result)) {

if (_.isFunction(config.catch)) {
this.validationError
this.fleek.validationError
yield config.catch.call(this, result, next);

} else {
Expand Down

0 comments on commit 3002113

Please sign in to comment.