yahoi
Version:
Yet Another Highly Opinionated Isomorphic Framework
52 lines (40 loc) • 1.01 kB
JavaScript
import Joi from 'joi';
export default class ParameterBag {
constructor(props) {
this.__parameters = Object.assign(props.parameters, props.body, props.routeParams);
this.__body = props.body;
this.__query = props.parameters;
this.__routeParams = props.routeParams;
this.__schema = {};
this.__autoReject = props.autoReject;
}
get(name, type) {
if(typeof(type=='undefined')) {
return this.__parameters[name];
}
}
getAllPostParameters() {
return this.__body;
}
list() {
return this.__parameters;
}
setSchema(schema) {
this.__schema = schema;
}
areNotValid() {
var result = Joi.validate(this.__parameters, this.__schema);
return result.error;
}
areValid() {
var result = Joi.validate(this.__parameters, this.__schema);
if(result.error) {
if(typeof(this.__autoReject)!='undefined') {
this.__autoReject(result);
}
return false;
} {
return true;
}
}
}