34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
|
|
const Promise = require("bluebird");
|
|
const db = require("../models/index");
|
|
const { allMarketAlerts } = require('../helpers/db/dbHelper');
|
|
const { createMarketAlertEmailTemplate, sendBulkEmail } = require('../helpers/awsEmail');
|
|
|
|
|
|
async function processNotifications() {
|
|
|
|
try {
|
|
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");
|
|
process.exit();
|
|
}
|
|
|
|
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);
|
|
process.exit();
|
|
}
|
|
}
|
|
|
|
processNotifications();
|