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-11-17 10:37:32 -08:00
|
|
|
const awaitingModeration = [
|
2020-12-03 06:01:26 -08:00
|
|
|
...(await db.all(`SELECT 'nouns' as type, locale, count(*) as c FROM nouns WHERE approved = 0 AND deleted=0 GROUP BY locale`)),
|
|
|
|
...(await db.all(`SELECT 'inclusive' as type, locale, count(*) as c FROM inclusive WHERE approved = 0 AND deleted=0 GROUP BY locale`)),
|
2020-12-06 06:23:18 -08:00
|
|
|
...(await db.all(`SELECT 'sources' as type, locale, count(*) as c FROM sources WHERE approved = 0 AND deleted=0 GROUP BY locale`)),
|
2020-11-17 10:37:32 -08:00
|
|
|
];
|
2020-10-31 05:26:16 -07:00
|
|
|
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 = {}
|
2020-11-17 10:37:32 -08:00
|
|
|
let count = 0;
|
2020-10-31 05:26:16 -07:00
|
|
|
for (let m of awaitingModeration) {
|
2020-11-17 10:37:32 -08:00
|
|
|
awaitingModerationGrouped[m.type + '-' + m.locale] = m.c;
|
|
|
|
count += m.c;
|
2020-10-31 05:26:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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-12-06 06:23:18 -08:00
|
|
|
'[Pronouns.page] Entries awaiting moderation: ' + count,
|
|
|
|
'Entries awaiting moderation: \n' + JSON.stringify(awaitingModerationGrouped, null, 4),
|
2020-10-31 05:26:16 -07:00
|
|
|
);
|
2020-08-06 07:33:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
notify();
|