Merge pull request #6343 from HabitRPG/api-v3-tasks2

[API v3] Tasks 2
This commit is contained in:
Matteo Pagliazzi
2015-12-16 13:18:05 +01:00
33 changed files with 2225 additions and 320 deletions
+10 -3
View File
@@ -1,7 +1,7 @@
/* eslint-disable no-use-before-define */
import {
assign,
set,
each,
isEmpty,
times,
@@ -277,16 +277,23 @@ function _updateDocument (collectionName, doc, update, cb) {
return cb();
}
// TODO use config for db url?
mongo.connect('mongodb://localhost/habitrpg_test', (connectErr, db) => {
if (connectErr) throw new Error(`Error connecting to database when updating ${collectionName} collection: ${connectErr}`);
let collection = db.collection(collectionName);
collection.update({ _id: doc._id }, { $set: update }, (updateErr) => {
collection.updateOne({ _id: doc._id }, { $set: update }, (updateErr) => {
if (updateErr) throw new Error(`Error updating ${collectionName}: ${updateErr}`);
assign(doc, update);
_updateLocalDocument(doc, update);
db.close();
cb();
});
});
}
function _updateLocalDocument (doc, update) {
each(update, (value, param) => {
set(doc, param, value);
});
}