2020-10-12 02:46:26 -07:00
|
|
|
const dbConnection = require('./db');
|
2020-08-06 07:33:16 -07:00
|
|
|
require('dotenv').config({ path:__dirname + '/../.env' });
|
2020-10-31 13:33:59 -07:00
|
|
|
const mailer = require('../src/mailer');
|
2020-08-06 07:33:16 -07:00
|
|
|
|
|
|
|
async function notify() {
|
2020-10-12 02:46:26 -07:00
|
|
|
const db = await dbConnection();
|
2020-08-06 07:33:16 -07:00
|
|
|
|
2020-10-31 05:26:16 -07:00
|
|
|
const awaitingModeration = (await db.all(`SELECT locale, count(*) as c FROM nouns WHERE approved = 0 GROUP BY locale`));
|
|
|
|
if (!awaitingModeration.length) {
|
2020-08-06 07:33:16 -07:00
|
|
|
console.log('No entries awaiting moderation');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-31 05:26:16 -07:00
|
|
|
const awaitingModerationGrouped = {}
|
|
|
|
for (let m of awaitingModeration) {
|
|
|
|
awaitingModerationGrouped[m.locale] = m.c;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Entries awaiting moderation: ', awaitingModerationGrouped);
|
2020-08-06 07:33:16 -07:00
|
|
|
|
|
|
|
for (let admin of process.env.MAILER_ADMINS.split(',')) {
|
|
|
|
console.log('Sending email to ' + admin)
|
2020-10-31 05:26:16 -07:00
|
|
|
mailer(
|
|
|
|
admin,
|
|
|
|
'[Pronouns] Dictionary entries awaiting moderation: ' + JSON.stringify(awaitingModerationGrouped),
|
|
|
|
JSON.stringify(awaitingModerationGrouped)
|
|
|
|
);
|
2020-08-06 07:33:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
notify();
|