29 lines
749 B
JavaScript
29 lines
749 B
JavaScript
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);
|
|
await createMarketAlertEmailTemplate();
|
|
if (marketAlerts.length > 0) {
|
|
await sendBulkEmail(marketAlerts);
|
|
}
|
|
|
|
await db.MarketAlert.update(
|
|
{ notified: true } /* set attributes' value */,
|
|
{ where: { notified: false } } /* where criteria */
|
|
);
|
|
} catch (e) {
|
|
console.log(
|
|
"NOTIFICATION SERVICE: could not send notifications reason: ",
|
|
e
|
|
);
|
|
}
|
|
}
|
|
|
|
module.exports = processNotifications;
|