mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
tests(api): Add sync method to api objects
This commit is contained in:
@@ -66,6 +66,20 @@ export async function updateDocument (collectionName, doc, update) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function getDocument (collectionName, doc) {
|
||||
let db = await connectToMongo();
|
||||
|
||||
let collection = db.collection(collectionName);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
collection.findOne({ _id: doc._id }, (lookupErr, found) => {
|
||||
if (lookupErr) throw new Error(`Error looking up ${collectionName}: ${lookupErr}`);
|
||||
db.close();
|
||||
resolve(found);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function connectToMongo () {
|
||||
return new Promise((resolve, reject) => {
|
||||
mongo.connect(DB_URI, (err, db) => {
|
||||
|
||||
Reference in New Issue
Block a user