diff --git a/api/controllers/send-email.js b/api/controllers/send-email.js index 4a83448..3b4324d 100644 --- a/api/controllers/send-email.js +++ b/api/controllers/send-email.js @@ -46,7 +46,8 @@ exports.post = async (req, res) => { }, comment: { content: commentInfo[0].content - } + }, + reply: commentInfo[0].reply || null } // Send notification notification.sendEmail(type, emailProps) diff --git a/api/routes/dev-view.js b/api/routes/dev-view.js index aefe4af..836110f 100644 --- a/api/routes/dev-view.js +++ b/api/routes/dev-view.js @@ -18,59 +18,60 @@ const basePath = NODE_ENV === 'production' ? '../../dist/templates' : '../../tem // return a // } -// function buildTemplate (fileName, props) { -// const path = `${basePath}/${fileName}` -// const reactTemplate = require(path) +function buildTemplate (fileName, props) { + const path = `${basePath}/${fileName}` + const reactTemplate = require(path) -// return reactTemplate({ ...props }) -// } + return reactTemplate({ ...props }) +} router.post('/test', async (req, res, next) => { try { - // const { type, comment } = req.body - // let commentInfo = await mongo.getDB().collection('comments').aggregate([ - // { $match: { _id: ObjectID(comment) } }, - // { - // $lookup: { - // from: 'users', - // localField: 'user', - // foreignField: '_id', - // as: 'user' - // } - // }, - // { - // $lookup: { - // from: 'documentversions', - // localField: 'version', - // foreignField: '_id', - // as: 'version' - // } - // }, - // { $project: { - // 'user.avatar': 0, - // 'version.content.fundation': 0, - // 'version.content.articles': 0, - // 'decoration': 0 - // } - // } - // ]).toArray() - // let emailProps = { - // author: { - // id: commentInfo[0].user[0]._id, - // name: commentInfo[0].user[0].name, - // fullname: commentInfo[0].user[0].fullname, - // email: commentInfo[0].user[0].email - // }, - // document: { - // id: commentInfo[0].document, - // title: commentInfo[0].version[0].content.title - // }, - // comment: { - // content: commentInfo[0].content - // } - // } - // const template = buildTemplate(type, emailProps) - // res.send(template) + const { type, comment } = req.body + let commentInfo = await mongo.getDB().collection('comments').aggregate([ + { $match: { _id: ObjectID(comment) } }, + { + $lookup: { + from: 'users', + localField: 'user', + foreignField: '_id', + as: 'user' + } + }, + { + $lookup: { + from: 'documentversions', + localField: 'version', + foreignField: '_id', + as: 'version' + } + }, + { $project: { + 'user.avatar': 0, + 'version.content.fundation': 0, + 'version.content.articles': 0, + 'decoration': 0 + } + } + ]).toArray() + let emailProps = { + author: { + id: commentInfo[0].user[0]._id, + name: commentInfo[0].user[0].name, + fullname: commentInfo[0].user[0].fullname, + email: commentInfo[0].user[0].email + }, + document: { + id: commentInfo[0].document, + title: commentInfo[0].version[0].content.title + }, + comment: { + content: commentInfo[0].content + }, + reply: commentInfo[0].reply || null + } + const template = buildTemplate(type, emailProps) + res.send(template) } catch (err) { res.status(INTERNAL_SERVER_ERROR).json({ message: 'An error ocurred', diff --git a/core/notification-strategies.js b/core/notification-strategies.js index 601f016..85bec59 100644 --- a/core/notification-strategies.js +++ b/core/notification-strategies.js @@ -29,6 +29,11 @@ const commentLiked = (info) => { execute(info.author.email, '¡Comentario relevante!', template) } +const commentReplied = (info) => { + const template = buildTemplate('comment-replied', info) + execute(info.author.email, '¡Comentario respondido!', template) +} + const commentContribution = (info) => { const template = buildTemplate('comment-contribution', info) execute(info.author.email, '¡Comentario marcado como aporte!', template) @@ -37,6 +42,7 @@ const commentContribution = (info) => { const strategies = [ ['comment-resolved', commentResolved], ['comment-liked', commentLiked], + ['comment-replied', commentReplied], ['comment-contribution', commentContribution] ] diff --git a/templates/comment-replied.js b/templates/comment-replied.js new file mode 100644 index 0000000..0e628c5 --- /dev/null +++ b/templates/comment-replied.js @@ -0,0 +1,56 @@ +const React = require('react') +const { Email, Item, Span, A, renderEmail, Box, Image } = require('react-html-email') +const MailHeader = require('./header') +const MailFooter = require('./footer') +const Content = require('./content') +const Style = require('./styles') +const CommentContainerStyle = require('./commentContainerStyle') +const { ORGANIZATION_NAME, ORGANIZATION_URL, ORGANIZATION_API_URL } = process.env + +const CommentRead = (props) => { + return ( + + + + + + El/la diputado/a respondió a su comentario en el proyecto {props.document.title} en {ORGANIZATION_NAME} + + + + + + +
+ +
+
+
+ + + {props.author.fullname} + +
+
+ + {props.comment.content} + +
+
+ + {props.reply} + +
+
+
+
+
+
+
+
+ +
+ ) +} + +module.exports = (props) => renderEmail() diff --git a/templates/commentContainerStyle.js b/templates/commentContainerStyle.js index 1c43825..568f114 100644 --- a/templates/commentContainerStyle.js +++ b/templates/commentContainerStyle.js @@ -52,3 +52,18 @@ module.exports.theCommentStyle = { lineHeight: 16, fontSize: 12 } + +module.exports.theReplyStyle = { + lineHeight: 16, + fontSize: 12 +} + +module.exports.replyContainerStyle = { + marginLeft: 10, + marginTop: 10, + paddingLeft: 10, + paddingTop: 5, + paddingBottom: 5, + borderLeft: '1px solid #CCC', + whiteSpace: 'pre-wrap' +}