db/SessionManager: use jshint

This commit is contained in:
booo 2011-12-22 12:02:28 +01:00
parent 8f208ca444
commit 1f41ef3365

View file

@ -31,9 +31,9 @@ exports.doesSessionExist = function(sessionID, callback)
db.get("session:" + sessionID, function (err, session) db.get("session:" + sessionID, function (err, session)
{ {
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
callback(null, session != null); callback(null, session ? true : false);
}); });
} };
/** /**
* Creates a new session between an author and a group * Creates a new session between an author and a group
@ -51,7 +51,7 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
//group does not exist //group does not exist
if(exists == false) if(!exists)
{ {
callback(new customError("groupID does not exist","apierror")); callback(new customError("groupID does not exist","apierror"));
} }
@ -70,7 +70,7 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
//author does not exist //author does not exist
if(exists == false) if(!exists)
{ {
callback(new customError("authorID does not exist","apierror")); callback(new customError("authorID does not exist","apierror"));
} }
@ -88,9 +88,9 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
if(typeof validUntil != "number") if(typeof validUntil != "number")
{ {
//try to parse the number //try to parse the number
if(!isNaN(parseInt(validUntil))) if(!isNaN(parseInt(validUntil, 10)))
{ {
validUntil = parseInt(validUntil); validUntil = parseInt(validUntil, 10);
} }
else else
{ {
@ -137,7 +137,7 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
//the entry doesn't exist so far, let's create it //the entry doesn't exist so far, let's create it
if(group2sessions == null) if(!group2sessions)
{ {
group2sessions = {sessionIDs : {}}; group2sessions = {sessionIDs : {}};
} }
@ -160,7 +160,7 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
//the entry doesn't exist so far, let's create it //the entry doesn't exist so far, let's create it
if(author2sessions == null) if(!author2sessions)
{ {
author2sessions = {sessionIDs : {}}; author2sessions = {sessionIDs : {}};
} }
@ -180,8 +180,8 @@ exports.createSession = function(groupID, authorID, validUntil, callback)
//return error and sessionID //return error and sessionID
callback(null, {sessionID: sessionID}); callback(null, {sessionID: sessionID});
}) });
} };
exports.getSessionInfo = function(sessionID, callback) exports.getSessionInfo = function(sessionID, callback)
{ {
@ -191,9 +191,9 @@ exports.getSessionInfo = function(sessionID, callback)
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
//session does not exists //session does not exists
if(session == null) if(session === null)
{ {
callback(new customError("sessionID does not exist","apierror")) callback(new customError("sessionID does not exist","apierror"));
} }
//everything is fine, return the sessioninfos //everything is fine, return the sessioninfos
else else
@ -201,7 +201,7 @@ exports.getSessionInfo = function(sessionID, callback)
callback(null, session); callback(null, session);
} }
}); });
} };
/** /**
* Deletes a session * Deletes a session
@ -220,9 +220,9 @@ exports.deleteSession = function(sessionID, callback)
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
//session does not exists //session does not exists
if(session == null) if(!session)
{ {
callback(new customError("sessionID does not exist","apierror")) callback(new customError("sessionID does not exist","apierror"));
} }
//everything is fine, return the sessioninfos //everything is fine, return the sessioninfos
else else
@ -274,8 +274,8 @@ exports.deleteSession = function(sessionID, callback)
{ {
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
callback(); callback();
}) });
} };
exports.listSessionsOfGroup = function(groupID, callback) exports.listSessionsOfGroup = function(groupID, callback)
{ {
@ -284,7 +284,7 @@ exports.listSessionsOfGroup = function(groupID, callback)
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
//group does not exist //group does not exist
if(exists == false) if(!exists)
{ {
callback(new customError("groupID does not exist","apierror")); callback(new customError("groupID does not exist","apierror"));
} }
@ -294,7 +294,7 @@ exports.listSessionsOfGroup = function(groupID, callback)
listSessionsWithDBKey("group2sessions:" + groupID, callback); listSessionsWithDBKey("group2sessions:" + groupID, callback);
} }
}); });
} };
exports.listSessionsOfAuthor = function(authorID, callback) exports.listSessionsOfAuthor = function(authorID, callback)
{ {
@ -303,7 +303,7 @@ exports.listSessionsOfAuthor = function(authorID, callback)
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
//group does not exist //group does not exist
if(exists == false) if(!exists)
{ {
callback(new customError("authorID does not exist","apierror")); callback(new customError("authorID does not exist","apierror"));
} }
@ -313,7 +313,7 @@ exports.listSessionsOfAuthor = function(authorID, callback)
listSessionsWithDBKey("author2sessions:" + authorID, callback); listSessionsWithDBKey("author2sessions:" + authorID, callback);
} }
}); });
} };
//this function is basicly the code listSessionsOfAuthor and listSessionsOfGroup has in common //this function is basicly the code listSessionsOfAuthor and listSessionsOfGroup has in common
function listSessionsWithDBKey (dbkey, callback) function listSessionsWithDBKey (dbkey, callback)
@ -376,5 +376,5 @@ function randomString(len)
//checks if a number is an int //checks if a number is an int
function is_int(value) function is_int(value)
{ {
return (parseFloat(value) == parseInt(value)) && !isNaN(value) return (parseFloat(value) == parseInt(value, 10)) && !isNaN(value);
} }