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
|
|
|
|
2020-11-05 08:44:11 -08:00
|
|
|
const admins = await db.all(`SELECT email FROM users WHERE roles = 'admin'`);
|
|
|
|
|
|
|
|
for (let { email } of admins) {
|
|
|
|
console.log('Sending email to ' + email)
|
2020-10-31 05:26:16 -07:00
|
|
|
mailer(
|
2020-11-05 08:44:11 -08:00
|
|
|
email,
|
2020-10-31 05:26:16 -07:00
|
|
|
'[Pronouns] Dictionary entries awaiting moderation: ' + JSON.stringify(awaitingModerationGrouped),
|
|
|
|
JSON.stringify(awaitingModerationGrouped)
|
|
|
|
);
|
2020-08-06 07:33:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
notify();
|