This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/server/notify.js

34 lines
1.0 KiB
JavaScript
Raw Normal View History

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