mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Add functionality to generate user to update user
This commit is contained in:
@@ -121,6 +121,7 @@
|
|||||||
"karma-script-launcher": "~0.1.0",
|
"karma-script-launcher": "~0.1.0",
|
||||||
"lcov-result-merger": "^1.0.2",
|
"lcov-result-merger": "^1.0.2",
|
||||||
"mocha": "~1.12.1",
|
"mocha": "~1.12.1",
|
||||||
|
"mongodb": "^2.0.46",
|
||||||
"mongoskin": "~0.6.1",
|
"mongoskin": "~0.6.1",
|
||||||
"protractor": "~2.0.0",
|
"protractor": "~2.0.0",
|
||||||
"rewire": "^2.3.3",
|
"rewire": "^2.3.3",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {isEmpty} from 'lodash';
|
import {isEmpty} from 'lodash';
|
||||||
|
import {MongoClient as mongo} from 'mongodb';
|
||||||
import {v4 as generateRandomUserName} from 'uuid';
|
import {v4 as generateRandomUserName} from 'uuid';
|
||||||
import superagent from 'superagent';
|
import superagent from 'superagent';
|
||||||
|
|
||||||
@@ -27,7 +28,9 @@ export function generateUser(update={}) {
|
|||||||
password: password,
|
password: password,
|
||||||
confirmPassword: password,
|
confirmPassword: password,
|
||||||
}).then((user) => {
|
}).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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user