summaryrefslogtreecommitdiff
path: root/app/node_modules
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-04-05 11:46:47 -0400
committerJules Laplace <jules@okfoc.us>2016-04-05 11:46:47 -0400
commitcd929e1c38c02c1d048abe702c04c7d4d6188011 (patch)
treeec2b32caa4a71f5de7e998c64e7e9dfd994b295e /app/node_modules
parent39b95380e6f81734d8a54bfbbfda13216d400247 (diff)
Fix sorting bug when savingv0.1.25
Diffstat (limited to 'app/node_modules')
-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)
};
/**