added deleteSession
This commit is contained in:
parent
dc15682a27
commit
f6b87daa27
|
@ -222,10 +222,73 @@ exports.getSessionInfo = function(sessionID, callback)
|
||||||
*/
|
*/
|
||||||
exports.deleteSession = function(sessionID, callback)
|
exports.deleteSession = function(sessionID, callback)
|
||||||
{
|
{
|
||||||
//check if session exits
|
var authorID, groupID;
|
||||||
//delete session
|
var group2sessions, author2sessions;
|
||||||
//delete group2sessions
|
|
||||||
//delete author2sessions
|
async.series([
|
||||||
|
function(callback)
|
||||||
|
{
|
||||||
|
//get the session entry
|
||||||
|
db.get("session:" + sessionID, function (err, session)
|
||||||
|
{
|
||||||
|
//error
|
||||||
|
if(err)
|
||||||
|
{
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
|
//session does not exists
|
||||||
|
else if(session == null)
|
||||||
|
{
|
||||||
|
callback({stop: "sessionID does not exist"})
|
||||||
|
}
|
||||||
|
//everything is fine, return the sessioninfos
|
||||||
|
else
|
||||||
|
{
|
||||||
|
authorID = session.authorID;
|
||||||
|
groupID = session.groupID;
|
||||||
|
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
//get the group2sessions entry
|
||||||
|
function(callback)
|
||||||
|
{
|
||||||
|
db.get("group2sessions:" + groupID, function (err, _group2sessions)
|
||||||
|
{
|
||||||
|
group2sessions = _group2sessions;
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
//get the author2sessions entry
|
||||||
|
function(callback)
|
||||||
|
{
|
||||||
|
db.get("author2sessions:" + authorID, function (err, _author2sessions)
|
||||||
|
{
|
||||||
|
author2sessions = _author2sessions;
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
//remove the values from the database
|
||||||
|
function(callback)
|
||||||
|
{
|
||||||
|
//remove the session
|
||||||
|
db.remove("session:" + sessionID);
|
||||||
|
|
||||||
|
//remove session from group2sessions
|
||||||
|
delete group2sessions.sessionIDs[sessionID];
|
||||||
|
db.set("group2sessions:" + groupID, group2sessions);
|
||||||
|
|
||||||
|
//remove session from author2sessions
|
||||||
|
delete author2sessions.sessionIDs[sessionID];
|
||||||
|
db.set("author2sessions:" + authorID, author2sessions);
|
||||||
|
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
], function(err)
|
||||||
|
{
|
||||||
|
callback(err);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.listSessionsOfGroup = function(groupID, callback)
|
exports.listSessionsOfGroup = function(groupID, callback)
|
||||||
|
@ -251,7 +314,7 @@ exports.listSessionsOfGroup = function(groupID, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.listSessionsOfAuthor = function(authorID, callback)
|
exports.listSessionsOfAuthor = function(authorID, callback)
|
||||||
{
|
{
|
||||||
authorMangager.doesAuthorExists(authorID, function(err, exists)
|
authorMangager.doesAuthorExists(authorID, function(err, exists)
|
||||||
{
|
{
|
||||||
//error
|
//error
|
||||||
|
@ -272,6 +335,7 @@ exports.listSessionsOfAuthor = function(authorID, callback)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//this function is basicly the code listSessionsOfAuthor and listSessionsOfGroup has in common
|
||||||
function listSessionsWithDBKey (dbkey, callback)
|
function listSessionsWithDBKey (dbkey, callback)
|
||||||
{
|
{
|
||||||
var sessions;
|
var sessions;
|
||||||
|
@ -287,7 +351,7 @@ function listSessionsWithDBKey (dbkey, callback)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function(callback)
|
function(callback)
|
||||||
{
|
{
|
||||||
//collect all sessionIDs in an arrary
|
//collect all sessionIDs in an arrary
|
||||||
var sessionIDs = [];
|
var sessionIDs = [];
|
||||||
for (var i in sessions)
|
for (var i in sessions)
|
||||||
|
|
|
@ -44,7 +44,7 @@ var functions = {
|
||||||
"createAuthor" : ["name"],
|
"createAuthor" : ["name"],
|
||||||
"createAuthorIfNotExistsFor" : ["authorMapper" , "name"],
|
"createAuthorIfNotExistsFor" : ["authorMapper" , "name"],
|
||||||
"createSession" : ["groupID", "authorID", "validUntil"],
|
"createSession" : ["groupID", "authorID", "validUntil"],
|
||||||
// "deleteSession" : ["sessionID"],
|
"deleteSession" : ["sessionID"],
|
||||||
"getSessionInfo" : ["sessionID"],
|
"getSessionInfo" : ["sessionID"],
|
||||||
"listSessionsOfGroup" : ["groupID"],
|
"listSessionsOfGroup" : ["groupID"],
|
||||||
"listSessionsOfAuthor" : ["authorID"],
|
"listSessionsOfAuthor" : ["authorID"],
|
||||||
|
|
Loading…
Reference in New Issue