var db = require("../utils/database");
-var maild = require("../utils/mailer.js");
var genToken = require("../utils/tokenGenerator");
var params = require("../config/parameters");
+var sendEmail = require('../utils/mailer');
/*
* Structure:
});
},
- getByName: function(names, cb) {
- db.serialize(function() {
- const query =
- "SELECT id " +
+ getByIds: function(ids, cb) {
+ db.serialize(function() {
+ const query =
+ "SELECT id, name " +
"FROM Users " +
- "WHERE name IN ('" + names.join("','") + "')";
- db.all(query, cb);
- });
+ "WHERE id IN (" + ids + ")";
+ db.all(query, cb);
+ });
},
/////////
db.run(query, cb);
});
},
+
+ /////////////////
+ // 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 || {});
+ });
+ });
+ }
}
module.exports = UserModel;