mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-13 07:18:38 +00:00
Add functionality to generate user to update user
This commit is contained in:
parent
7f6b392511
commit
75f63b1367
2 changed files with 20 additions and 1 deletions
|
|
@ -121,6 +121,7 @@
|
|||
"karma-script-launcher": "~0.1.0",
|
||||
"lcov-result-merger": "^1.0.2",
|
||||
"mocha": "~1.12.1",
|
||||
"mongodb": "^2.0.46",
|
||||
"mongoskin": "~0.6.1",
|
||||
"protractor": "~2.0.0",
|
||||
"rewire": "^2.3.3",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import {isEmpty} from 'lodash';
|
||||
import {MongoClient as mongo} from 'mongodb';
|
||||
import {v4 as generateRandomUserName} from 'uuid';
|
||||
import superagent from 'superagent';
|
||||
|
||||
|
|
@ -27,7 +28,9 @@ export function generateUser(update={}) {
|
|||
password: password,
|
||||
confirmPassword: password,
|
||||
}).then((user) => {
|
||||
resolve(user);
|
||||
_updateDocument('users', user._id, update, () => {
|
||||
resolve(user);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
@ -55,3 +58,18 @@ function _requestMaker(user, method) {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
function _updateDocument(collectionName, uuid, update, cb) {
|
||||
if (isEmpty(update)) { return cb(); }
|
||||
|
||||
mongo.connect('mongodb://localhost/habitrpg_test', (err, db) => {
|
||||
if (err) throw `Error connecting to database when updating ${collectionName} collection: ${err}`;
|
||||
|
||||
let collection = db.collection(collectionName);
|
||||
|
||||
collection.update({ _id: uuid }, { $set: update }, (err, result) => {
|
||||
if (err) throw `Error updating ${collectionName}: ${err}`;
|
||||
cb();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue