2019-06-25 17:06:07 +02:00
|
|
|
|
|
|
|
|
const Promise = require("bluebird");
|
|
|
|
|
const db = require("../models/index");
|
|
|
|
|
const { allMarketAlerts } = require('../helpers/db/dbHelper');
|
2019-06-27 17:29:57 +02:00
|
|
|
const { createMarketAlertEmailTemplate, sendBulkEmail } = require('../helpers/awsEmail');
|
2019-06-25 17:06:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
async function processNotifications() {
|
|
|
|
|
|
|
|
|
|
try {
|
2019-06-28 18:06:19 +02:00
|
|
|
const marketAlerts = await allMarketAlerts(false, false);
|
|
|
|
|
console.log(marketAlerts.length)
|
|
|
|
|
await createMarketAlertEmailTemplate();
|
|
|
|
|
if (marketAlerts.length > 0) {
|
|
|
|
|
console.log("NOTIFICATION SERVICE: Number of new alerts: " + marketAlerts.length)
|
|
|
|
|
await sendBulkEmail(marketAlerts);
|
|
|
|
|
} else {
|
|
|
|
|
console.log("NOTIFICATION SERVICE: No new alerts");
|
2019-07-02 21:49:56 +02:00
|
|
|
process.exit();
|
2019-06-28 18:06:19 +02:00
|
|
|
}
|
2019-06-27 17:29:57 +02:00
|
|
|
|
2019-06-28 18:06:19 +02:00
|
|
|
await db.MarketAlert.update(
|
|
|
|
|
{ notified: true }, /* set attributes' value */
|
|
|
|
|
{ where: { notified: false } } /* where criteria */
|
|
|
|
|
);
|
2019-06-25 17:06:07 +02:00
|
|
|
process.exit();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log("NOTIFICATION SERVICE: could not send notifications reason: ", e);
|
2019-07-02 21:49:56 +02:00
|
|
|
process.exit();
|
2019-06-25 17:06:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-27 17:29:57 +02:00
|
|
|
processNotifications();
|