db/SessionManager.js: completely converted to Promises/async

pull/3559/head
Ray Bellis 2019-01-28 14:44:36 +00:00
parent e58da69cfb
commit 005c0afa97
1 changed files with 11 additions and 17 deletions

View File

@ -18,13 +18,11 @@
* limitations under the License.
*/
var ERR = require("async-stacktrace");
var customError = require("../utils/customError");
var randomString = require("../utils/randomstring");
var db = require("./DB");
var groupManager = require("./GroupManager");
var authorManager = require("./AuthorManager");
const thenify = require("thenify").withCallback;
exports.doesSessionExist = async function(sessionID)
{
@ -120,23 +118,19 @@ exports.createSession = async function(groupID, authorID, validUntil)
return { sessionID };
}
// @TODO once external dependencies are using Promises
exports.getSessionInfo = thenify(function(sessionID, callback)
exports.getSessionInfo = async function(sessionID)
{
// check if the database entry of this session exists
db.get("session:" + sessionID, function (err, session)
{
if(ERR(err, callback)) return;
let session = await db.get("session:" + sessionID);
if (session == null) {
// session does not exist
callback(new customError("sessionID does not exist", "apierror"))
} else {
// everything is fine, return the sessioninfos
callback(null, session);
throw new customError("sessionID does not exist", "apierror");
}
// everything is fine, return the sessioninfos
return session;
}
});
});
/**
* Deletes a session
@ -199,7 +193,7 @@ exports.listSessionsOfAuthor = async function(authorID)
// this function is basically the code listSessionsOfAuthor and listSessionsOfGroup has in common
// required to return null rather than an empty object if there are none
async function listSessionsWithDBKey(dbkey, callback)
async function listSessionsWithDBKey(dbkey)
{
// get the group2sessions entry
let sessionObject = await db.get(dbkey);