Skip to content

Commit

Permalink
Merge pull request #4 from DemocraciaEnRed/1.2.0
Browse files Browse the repository at this point in the history
Ready for 1.2.0
  • Loading branch information
guillecro authored Apr 9, 2019
2 parents 5090d5f + 61b9358 commit af209ee
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 50 deletions.
3 changes: 2 additions & 1 deletion api/controllers/send-email.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
99 changes: 50 additions & 49 deletions api/routes/dev-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions core/notification-strategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -37,6 +42,7 @@ const commentContribution = (info) => {
const strategies = [
['comment-resolved', commentResolved],
['comment-liked', commentLiked],
['comment-replied', commentReplied],
['comment-contribution', commentContribution]
]

Expand Down
56 changes: 56 additions & 0 deletions templates/comment-replied.js
Original file line number Diff line number Diff line change
@@ -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 (
<Email title='Comentario resuelto' style={{ width: '100%', maxWidth: '700px' }}>
<MailHeader />
<Content name={props.author.name} style={{ width: '100%' }}>
<Item style={Style.itemStyle}>
<Span {...Style.defaultContentStyle}>
El/la diputado/a respondió a su comentario en el proyecto <b>{props.document.title}</b> en <A href={`${ORGANIZATION_URL}/propuesta?id=${props.document.id}`}>{ORGANIZATION_NAME}</A>
</Span>
</Item>
<Item style={Style.itemStyle}>
<A href={`${ORGANIZATION_URL}/propuesta?id=${props.document.id}`} textDecoration='none'>
<Box align='center' style={CommentContainerStyle.cardStyle}>
<Item>
<div style={CommentContainerStyle.leftColumn} >
<Image src={`${ORGANIZATION_URL}/static/assets/emails/check.png`} style={CommentContainerStyle.cardIconImg} />
</div>
<div style={CommentContainerStyle.cardContentStyle}>
<div style={CommentContainerStyle.userContainerStyle}>
<Span {...CommentContainerStyle.userNameStyle}>
<Image src={`${ORGANIZATION_API_URL}/api/v1/users/${props.author.id}`} style={CommentContainerStyle.userAvatarStyle} />
{props.author.fullname}
</Span>
</div>
<div>
<Span {...CommentContainerStyle.theCommentStyle}>
{props.comment.content}
</Span>
<br />
<div style={CommentContainerStyle.replyContainerStyle}>
<Span {...CommentContainerStyle.theReplyStyle}>
{props.reply}
</Span>
</div>
</div>
</div>
</Item>
</Box>
</A>
</Item>
</Content>
<MailFooter />
</Email>
)
}

module.exports = (props) => renderEmail(<CommentRead {...props} />)
15 changes: 15 additions & 0 deletions templates/commentContainerStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

0 comments on commit af209ee

Please sign in to comment.