Commit 4ad887e3 authored by Tristan Cavelier's avatar Tristan Cavelier

revisionstorage.js upgraded to JIO v2

parent f51d8d5f
...@@ -293,6 +293,7 @@ ...@@ -293,6 +293,7 @@
}; };
priv.send = function (command, method, doc, option, callback) { priv.send = function (command, method, doc, option, callback) {
var storage = command.storage(priv.sub_storage);
function onSuccess(success) { function onSuccess(success) {
callback(undefined, success); callback(undefined, success);
} }
...@@ -300,11 +301,9 @@ ...@@ -300,11 +301,9 @@
callback(err, undefined); callback(err, undefined);
} }
if (method === 'allDocs') { if (method === 'allDocs') {
command.storage(priv.sub_storage).allDocs(option). storage.allDocs(option).then(onSuccess, onError);
then(onSuccess, onError);
} else { } else {
command.storage(priv.sub_storage)[method](doc, option). storage[method](doc, option).then(onSuccess, onError);
then(onSuccess, onError);
} }
}; };
...@@ -399,7 +398,15 @@ ...@@ -399,7 +398,15 @@
priv.getRevisionTree = function (command, doc, option, callback) { priv.getRevisionTree = function (command, doc, option, callback) {
doc = priv.clone(doc); doc = priv.clone(doc);
doc._id = doc._id + priv.doc_tree_suffix; doc._id = doc._id + priv.doc_tree_suffix;
priv.get(command, doc, option, callback); priv.get(command, doc, option, function (err, response) {
if (err) {
return callback(err, response);
}
if (response.data && response.data.children) {
response.data.children = JSON.parse(response.data.children);
}
return callback(err, response);
});
}; };
priv.getAttachmentList = function (command, doc, option, callback) { priv.getAttachmentList = function (command, doc, option, callback) {
...@@ -441,7 +448,7 @@ ...@@ -441,7 +448,7 @@
} }
} }
if (count === 0) { if (count === 0) {
callback(undefined, []); callback(undefined, {"data": []});
} }
}; };
...@@ -481,14 +488,15 @@ ...@@ -481,14 +488,15 @@
priv.putDocumentTree = function (command, doc, option, doc_tree, callback) { priv.putDocumentTree = function (command, doc, option, doc_tree, callback) {
doc_tree = priv.clone(doc_tree); doc_tree = priv.clone(doc_tree);
doc_tree._id = doc._id + priv.doc_tree_suffix; doc_tree._id = doc._id + priv.doc_tree_suffix;
if (doc_tree.children) {
doc_tree.children = JSON.stringify(doc_tree.children);
}
priv.put(command, doc_tree, option, callback); priv.put(command, doc_tree, option, callback);
}; };
priv.notFoundError = function (message, reason) { priv.notFoundError = function (message, reason) {
return { return {
"status": 404, "status": "not_found",
"statusText": "Not Found",
"error": "not_found",
"message": message, "message": message,
"reason": reason "reason": reason
}; };
...@@ -496,9 +504,7 @@ ...@@ -496,9 +504,7 @@
priv.conflictError = function (message, reason) { priv.conflictError = function (message, reason) {
return { return {
"status": 409, "status": "conflict",
"statusText": "Conflict",
"error": "conflict",
"message": message, "message": message,
"reason": reason "reason": reason
}; };
...@@ -539,7 +545,7 @@ ...@@ -539,7 +545,7 @@
return onEnd(err, undefined); return onEnd(err, undefined);
} }
} }
doc_tree = response.data || priv.newDocTree(); doc_tree = (response && response.data) || priv.newDocTree();
if (specific_parameter.get || specific_parameter.getAttachment) { if (specific_parameter.get || specific_parameter.getAttachment) {
if (!doc._rev) { if (!doc._rev) {
winner_info = priv.getWinnerRevsInfo(doc_tree); winner_info = priv.getWinnerRevsInfo(doc_tree);
...@@ -600,7 +606,7 @@ ...@@ -600,7 +606,7 @@
"missing" "missing"
), undefined); ), undefined);
} }
priv.putDocument(doc, option, callback.putDocument); priv.putDocument(command, doc, option, callback.putDocument);
}; };
callback.getDocument = function (err, res_doc) { callback.getDocument = function (err, res_doc) {
var k, conflicts; var k, conflicts;
...@@ -619,12 +625,13 @@ ...@@ -619,12 +625,13 @@
"missing" "missing"
), undefined); ), undefined);
} }
res_doc = {}; res_doc = {"data":{}};
} else { } else {
err.message = "Cannot get document"; err.message = "Cannot get document";
return onEnd(err, undefined); return onEnd(err, undefined);
} }
} }
res_doc = res_doc.data;
if (specific_parameter.get) { if (specific_parameter.get) {
res_doc._id = doc._id; res_doc._id = doc._id;
res_doc._rev = doc._rev; res_doc._rev = doc._rev;
...@@ -665,6 +672,7 @@ ...@@ -665,6 +672,7 @@
err.message = "Cannot get attachment"; err.message = "Cannot get attachment";
return onEnd(err, undefined); return onEnd(err, undefined);
} }
res_list = res_list.data;
attachment_list = res_list || []; attachment_list = res_list || [];
if (specific_parameter.getAttachment) { if (specific_parameter.getAttachment) {
// getting specific attachment // getting specific attachment
...@@ -745,7 +753,6 @@ ...@@ -745,7 +753,6 @@
return onEnd(err, undefined); return onEnd(err, undefined);
} }
response_object = { response_object = {
"ok": true,
"id": doc._id, "id": doc._id,
"rev": doc._rev "rev": doc._rev
}; };
...@@ -784,7 +791,7 @@ ...@@ -784,7 +791,7 @@
if (err) { if (err) {
return command.error(err); return command.error(err);
} }
command.success({"id": response.id}); command.success({"id": response.id, "rev": response.rev});
} }
); );
}; };
......
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