added deleteSession

This commit is contained in:
Peter 'Pita' Martischka 2011-08-10 14:04:28 +01:00
parent dc15682a27
commit f6b87daa27
2 changed files with 71 additions and 7 deletions

View file

@ -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)
@ -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;

View file

@ -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"],