summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/node_modules/okschema/index.js23
1 files changed, 20 insertions, 3 deletions
diff --git a/app/node_modules/okschema/index.js b/app/node_modules/okschema/index.js
index cf041fb..8162fd4 100644
--- a/app/node_modules/okschema/index.js
+++ b/app/node_modules/okschema/index.js
@@ -174,8 +174,7 @@ function OKSchema(spec) {
});
}
-OKSchema.prototype.checkDataForMissingArrays = function(data) {
- data = data || {};
+OKSchema.prototype.fixMissingLists = function(data) {
var spec = this.spec;
// The qs body-parser module does not have a way to represent
@@ -189,10 +188,22 @@ OKSchema.prototype.checkDataForMissingArrays = function(data) {
})
}
+OKSchema.prototype.fixIndexField = function(data) {
+ // Likewise numbers always come in as strings. The field used to sort
+ // records, __index, is of type "meta", so the parseFloat in
+ // assertValid (below) never fires and we end up with sorting issues.
+ if (data.__index && typeof data.__index == "string") {
+ var __index = parseInt(data.__index)
+ if (! isNaN(__index)) {
+ data.__index = __index
+ }
+ }
+}
+
OKSchema.prototype.assertValid = function(data) {
data = data || {};
var spec = this.spec;
- this.checkDataForMissingArrays(data)
+
// Run through custom validators, they'll throw if invalid
Object.keys(data).forEach(function(prop) {
var type = spec[prop].type;
@@ -210,6 +221,12 @@ OKSchema.prototype.assertValid = function(data) {
if (!result.valid) {
throw result.errors;
}
+
+ // Fix various issues with our data, having to do
+ // with use of the "qs" body-parser module.
+ // TODO: just send JSON?
+ this.fixMissingLists(data)
+ this.fixIndexField(data)
};
/**