Send templated bulk email, and remember notifed marketalerts

This commit is contained in:
Nedim Uka
2019-06-28 18:06:19 +02:00
parent b3baffe174
commit 96e9da1fb1
7 changed files with 98 additions and 61 deletions

View File

@@ -8,11 +8,20 @@ const { createMarketAlertEmailTemplate, sendBulkEmail } = require('../helpers/aw
async function processNotifications() {
try {
const marketAlerts = await allMarketAlerts(false);
// await createMarketAlertEmailTemplate();
await sendBulkEmail(marketAlerts);
// console.log(marketAlerts);
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");
}
await db.MarketAlert.update(
{ notified: true }, /* set attributes' value */
{ where: { notified: false } } /* where criteria */
);
process.exit();
} catch (e) {
console.log("NOTIFICATION SERVICE: could not send notifications reason: ", e);