Created
September 1, 2014 08:38
-
-
Save cjroth/6d86854b5db809c8746f to your computer and use it in GitHub Desktop.
node/express last active middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function() { | |
return function(req, res, next) { | |
if (!req.user) return next(); | |
var sql = req.app.services.sql; | |
sql | |
.query('update users set last_active = $1 where id = $2;', [new Date(), req.user.id]) | |
.on('error', function(err) { | |
console.error(err); | |
}); | |
next(); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment