diff options
| author | Jules Laplace <jules@okfoc.us> | 2016-04-06 19:11:22 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2016-04-06 19:11:22 -0400 |
| commit | 654053736a74aa8cd4344e9c4f5e5a7ebeefc33e (patch) | |
| tree | 42a9be805974f4ae40d33f16dce58404aa983cd8 /app/node_modules/okschema/index.js | |
| parent | 6c09824946214db696beb59e34ce2e448d504abc (diff) | |
Store booleans as type boolean
Diffstat (limited to 'app/node_modules/okschema/index.js')
| -rw-r--r-- | app/node_modules/okschema/index.js | 13 |
1 files changed, 8 insertions, 5 deletions
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()); |
