Commit 23242819 authored by Tristan Cavelier's avatar Tristan Cavelier

gidstorage.js put method done

parent 63d104a0
...@@ -296,7 +296,7 @@ ...@@ -296,7 +296,7 @@
}; };
}; };
that.post = function (command) { priv.putOrPost = function (command, method) {
setTimeout(function () { setTimeout(function () {
var gid, complex_query, doc = command.cloneDoc(); var gid, complex_query, doc = command.cloneDoc();
gid = gidFormat(doc, priv.constraints); gid = gidFormat(doc, priv.constraints);
...@@ -305,7 +305,7 @@ ...@@ -305,7 +305,7 @@
"status": 409, "status": 409,
"statusText": "Conflict", "statusText": "Conflict",
"error": "conflict", "error": "conflict",
"message": "Cannot post document", "message": "Cannot " + method + " document",
"reason": "metadata should respect constraints" "reason": "metadata should respect constraints"
}); });
} }
...@@ -314,8 +314,9 @@ ...@@ -314,8 +314,9 @@
"query": complex_query, "query": complex_query,
"wildcard_character": null "wildcard_character": null
}, function (response) { }, function (response) {
var doc; var doc, update_method = method;
if (response.total_rows !== 0) { if (response.total_rows !== 0) {
if (method === 'post') {
return that.error({ return that.error({
"status": 409, "status": 409,
"statusText": "Conflict", "statusText": "Conflict",
...@@ -323,24 +324,38 @@ ...@@ -323,24 +324,38 @@
"message": "Cannot post document", "message": "Cannot post document",
"reason": "Document already exist" "reason": "Document already exist"
}); });
} else {
doc = command.cloneDoc();
doc._id = response.rows[0].id;
} }
} else {
doc = command.cloneDoc(); doc = command.cloneDoc();
delete doc._id; delete doc._id;
that.addJob('post', priv.sub_storage, doc, { update_method = 'post';
}
that.addJob(update_method, priv.sub_storage, doc, {
}, function (response) { }, function (response) {
response.id = gid; response.id = gid;
that.success(response); that.success(response);
}, function (err) { }, function (err) {
err.message = "Cannot post document"; err.message = "Cannot " + method + " document";
that.error(err); that.error(err);
}); });
}, function (err) { }, function (err) {
err.message = "Cannot post document"; err.message = "Cannot " + method + " document";
that.error(err); that.error(err);
}); });
}); });
}; };
that.post = function (command) {
priv.putOrPost(command, 'post');
};
that.put = function (command) {
priv.putOrPost(command, 'put');
};
that.get = function (command) { that.get = function (command) {
setTimeout(function () { setTimeout(function () {
var gid_object, complex_query; var gid_object, complex_query;
......
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