From 005c0afa97e348e95a9ff8ee8ff0e480c6daf4f1 Mon Sep 17 00:00:00 2001 From: Ray Bellis Date: Mon, 28 Jan 2019 14:44:36 +0000 Subject: [PATCH] db/SessionManager.js: completely converted to Promises/async --- src/node/db/SessionManager.js | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/node/db/SessionManager.js b/src/node/db/SessionManager.js index 67d3e3816..9161205d7 100644 --- a/src/node/db/SessionManager.js +++ b/src/node/db/SessionManager.js @@ -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); - } - }); -}); + if (session == null) { + // session does not exist + 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);