From 654053736a74aa8cd4344e9c4f5e5a7ebeefc33e Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 6 Apr 2016 19:11:22 -0400 Subject: Store booleans as type boolean --- app/node_modules/okschema/index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'app/node_modules/okschema/index.js') diff --git a/app/node_modules/okschema/index.js b/app/node_modules/okschema/index.js index 8162fd4..b3d4cc2 100644 --- a/app/node_modules/okschema/index.js +++ b/app/node_modules/okschema/index.js @@ -66,7 +66,7 @@ var types = { assertValid: function(spec, value) {} }, 'flag': { - parent: 'string', + parent: 'boolean', assertValid: function(spec, value) {} }, 'foreign-key': { @@ -207,14 +207,17 @@ OKSchema.prototype.assertValid = function(data) { // Run through custom validators, they'll throw if invalid Object.keys(data).forEach(function(prop) { var type = spec[prop].type; - if (types[type]) { - types[type].assertValid(spec[prop], data[prop]); - // Also check if it's a number type and try to cast it + + // Check if it's a number/boolean and try to cast it // otherwise pass and let mschema handle - } else if (type === 'number') { + if (type === 'number') { try { data[prop] = parseFloat(data[prop]); } catch (err) {} + } else if (type === 'flag') { + data[prop] = data[prop] == "true" ? true : false + } else if (types[type]) { + types[type].assertValid(spec[prop], data[prop]); } }); var result = mschema.validate(data, this.toMschema()); -- cgit v1.2.3-70-g09d2