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,33 +314,48 @@ ...@@ -314,33 +314,48 @@
"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) {
return that.error({ if (method === 'post') {
"status": 409, return that.error({
"statusText": "Conflict", "status": 409,
"error": "conflict", "statusText": "Conflict",
"message": "Cannot post document", "error": "conflict",
"reason": "Document already exist" "message": "Cannot post document",
}); "reason": "Document already exist"
});
} else {
doc = command.cloneDoc();
doc._id = response.rows[0].id;
}
} else {
doc = command.cloneDoc();
delete doc._id;
update_method = 'post';
} }
doc = command.cloneDoc(); that.addJob(update_method, priv.sub_storage, doc, {
delete doc._id;
that.addJob('post', 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