forked from DemocraciaEnRed/leyesabiertas-notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solución al envío de mail al administrador
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,30 @@ exports.post = async (req, res) => { | |
.toArray() | ||
log(`Document has ${tagsData.length} tags: "${tagsData.map(t=>t.name).join('", "')}"`) | ||
|
||
|
||
// Notificamos a la cuenta de administrador del sistema | ||
try { | ||
|
||
notification.sendEmail('document-published', { | ||
user: { | ||
email: '[email protected]', | ||
name: "Admin" | ||
}, | ||
document: { | ||
id: documentObj._id, | ||
title: currentVersionObj.content.title, | ||
author: documentObj.authorObj.fullname || documentObj.authorObj.username | ||
}, | ||
matchingTags: [] | ||
}) | ||
|
||
} catch (err) { | ||
|
||
log(`Error when sending mail to admin:`) | ||
log(err) | ||
|
||
} | ||
|
||
// Buscamos todxs lxs usuarixs suscriptos a 1 o más de las etiquetas | ||
const users = await db.collection('users') | ||
.find({$and: [ | ||
|
@@ -123,6 +147,7 @@ exports.post = async (req, res) => { | |
}) | ||
|
||
// Devolvemos OK | ||
const result = await db.collection('documents').updateOne({ _id: ObjectID(documentId) }, { $set: { publishedMailSent: true } }) | ||
log(`${emailsSent} email(s) scheduled`) | ||
res.status(OK).json({ | ||
message: `${emailsSent} email(s) scheduled` | ||
|