UNPKG

yahoi

Version:

Yet Another Highly Opinionated Isomorphic Framework

48 lines (37 loc) 950 B
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 = {}; // console.log('props.autoReject', props.autoReject); 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; } areValid() { var result = Joi.validate(this.__parameters, this.__schema); if(result.error) { if(typeof(this.__autoReject)!='undefined') { this.__autoReject(result); } return false; } { return true; } } }