Commit 74d8752d authored by Vincent Bechu's avatar Vincent Bechu

mappingstorage: fix post when id is mapped

parent c0733eb3
......@@ -10,6 +10,12 @@
if (storage._no_sub_query_id) {
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({
key: key,
value: value,
......@@ -30,13 +36,13 @@
"limit": storage._query.limit
})
.push(function (data) {
if (data.data.rows.length === 0) {
if (data.data.total_rows === 0) {
throw new jIO.util.jIOError(
"Can not find id",
"Can not find document with (" + key + ", " + value + ")",
404
);
}
if (data.data.rows.length > 1) {
if (data.data.total_rows > 1) {
throw new TypeError("id must be unique field: " + key
+ ", result:" + data.data.rows.toString());
}
......@@ -63,9 +69,6 @@
doc.hasOwnProperty(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]);
},
......@@ -342,7 +345,7 @@
if (this._property_for_sub_id && id !== undefined) {
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)
.push(function (sub_id) {
return storage._sub_storage.put(sub_id, sub_doc);
......
......@@ -654,7 +654,7 @@
test("with id equalSubProperty and id in doc", function () {
stop();
expect(3);
expect(2);
var jio = jIO.createJIO({
type: "mapping",
......@@ -664,9 +664,14 @@
}
});
Storage2713.prototype.buildQuery = function (options) {
equal(options.query, 'otherId: "bar"', "allDoc 2713 called");
return [];
};
Storage2713.prototype.post = function (doc) {
deepEqual(doc, {"title": "foo", "otherId": "bar"}, "post 2713 called");
return "42";
return "bar";
};
Storage2713.prototype.put = function (id, doc) {
......@@ -675,7 +680,7 @@
"title": "foo",
"otherId": "bar"
}, "put 2713 called");
return "42";
return "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