Commit 1d8863cf authored by Vincent Bechu's avatar Vincent Bechu

mappingstorage: fix post when id is mapped

parent e14074b0
...@@ -10,6 +10,12 @@ ...@@ -10,6 +10,12 @@
if (storage._no_sub_query_id) { if (storage._no_sub_query_id) {
throw new jIO.util.jIOError('no sub query id active', 404); throw new jIO.util.jIOError('no sub query id active', 404);
} }
if (value === undefined) {
throw new jIO.util.jIOError(
'can not find document with ' + key + ' : undefined',
404
);
}
query = new SimpleQuery({ query = new SimpleQuery({
key: key, key: key,
value: value, value: value,
...@@ -30,13 +36,13 @@ ...@@ -30,13 +36,13 @@
"limit": storage._query.limit "limit": storage._query.limit
}) })
.push(function (data) { .push(function (data) {
if (data.data.rows.length === 0) { if (data.data.total_rows === 0) {
throw new jIO.util.jIOError( throw new jIO.util.jIOError(
"Can not find id", "Can not find document with (" + key + ", " + value + ")",
404 404
); );
} }
if (data.data.rows.length > 1) { if (data.data.total_rows > 1) {
throw new TypeError("id must be unique field: " + key throw new TypeError("id must be unique field: " + key
+ ", result:" + data.data.rows.toString()); + ", result:" + data.data.rows.toString());
} }
...@@ -63,9 +69,6 @@ ...@@ -63,9 +69,6 @@
doc.hasOwnProperty(storage._property_for_sub_id)) { doc.hasOwnProperty(storage._property_for_sub_id)) {
return doc[storage._property_for_sub_id]; return doc[storage._property_for_sub_id];
} }
if (doc.hasOwnProperty(args)) {
return doc[args];
}
} }
return getSubIdEqualSubProperty(storage, id, storage._map_id[1]); return getSubIdEqualSubProperty(storage, id, storage._map_id[1]);
}, },
...@@ -342,7 +345,7 @@ ...@@ -342,7 +345,7 @@
if (this._property_for_sub_id && id !== undefined) { if (this._property_for_sub_id && id !== undefined) {
return this._sub_storage.put(id, sub_doc); return this._sub_storage.put(id, sub_doc);
} }
if (!this._id_mapped || doc[this._id_mapped] !== undefined) { if (this._id_mapped && doc[this._id_mapped] !== undefined) {
return getSubStorageId(storage, id, doc) return getSubStorageId(storage, id, doc)
.push(function (sub_id) { .push(function (sub_id) {
return storage._sub_storage.put(sub_id, sub_doc); return storage._sub_storage.put(sub_id, sub_doc);
......
...@@ -654,7 +654,7 @@ ...@@ -654,7 +654,7 @@
test("with id equalSubProperty and id in doc", function () { test("with id equalSubProperty and id in doc", function () {
stop(); stop();
expect(3); expect(2);
var jio = jIO.createJIO({ var jio = jIO.createJIO({
type: "mapping", type: "mapping",
...@@ -664,9 +664,14 @@ ...@@ -664,9 +664,14 @@
} }
}); });
Storage2713.prototype.buildQuery = function (options) {
equal(options.query, 'otherId: "bar"', "allDoc 2713 called");
return [];
};
Storage2713.prototype.post = function (doc) { Storage2713.prototype.post = function (doc) {
deepEqual(doc, {"title": "foo", "otherId": "bar"}, "post 2713 called"); deepEqual(doc, {"title": "foo", "otherId": "bar"}, "post 2713 called");
return "42"; return "bar";
}; };
Storage2713.prototype.put = function (id, doc) { Storage2713.prototype.put = function (id, doc) {
...@@ -675,7 +680,7 @@ ...@@ -675,7 +680,7 @@
"title": "foo", "title": "foo",
"otherId": "bar" "otherId": "bar"
}, "put 2713 called"); }, "put 2713 called");
return "42"; return "bar";
}; };
jio.post({"title": "foo", "otherId": "bar"}) jio.post({"title": "foo", "otherId": "bar"})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment