+
+ /////////////////
+ // NOTIFICATIONS
+
+ tryNotify: function(oppId, message)
+ {
+ UserModel.getOne("id", oppId, (err,opp) => {
+ if (!err || !opp.notify)
+ return; //error is ignored here (TODO: should be logged)
+ const subject = "vchess.club - notification";
+ const body = "Hello " + opp.name + "!\n" + message;
+ sendEmail(params.mail.noreply, opp.email, subject, body, err => {
+ res.json(err || {});
+ });
+ });
+ },
+
+ ////////////
+ // CLEANING
+
+ cleanUsersDb: function()
+ {
+ const tsNow = Date.now();
+ // 86400000 = 24 hours in milliseconds
+ const day = 86400000;
+ db.serialize(function() {
+ const query =
+ "SELECT id, sessionToken, created " +
+ "FROM Users";
+ db.all(query, (err, users) => {
+ users.forEach(u => {
+ // Remove unlogged users for >1 day
+ if (!u.sessionToken && tsNow - u.created > day)
+ db.run("DELETE FROM Users WHERE id = " + u.id);
+ });
+ });
+ });
+ },