-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from DemocraciaEnRed/1.3.0
Ready for 1.3.0
- Loading branch information
Showing
10 changed files
with
197 additions
and
25 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
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const { INTERNAL_SERVER_ERROR, OK } = require('http-status') | ||
const { ObjectID } = require('mongodb') | ||
const mongo = require('../../services/db') | ||
const notification = require('../../core/notification-strategies') | ||
|
||
exports.post = async (req, res) => { | ||
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' | ||
} | ||
}, | ||
{ | ||
$lookup: { | ||
from: 'documents', | ||
localField: 'document', | ||
foreignField: '_id', | ||
as: 'document' | ||
} | ||
}, | ||
{ | ||
$lookup: { | ||
from: 'users', | ||
localField: 'document.author', | ||
foreignField: '_id', | ||
as: 'author' | ||
} | ||
}, | ||
{ $project: { | ||
'user.avatar': 0, | ||
'author.avatar': 0, | ||
'version.content.fundation': 0, | ||
'version.content.articles': 0, | ||
'decoration': 0 | ||
} | ||
} | ||
]).toArray() | ||
// Prepare email props | ||
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[0]._id, | ||
title: commentInfo[0].version[0].content.title | ||
}, | ||
comment: { | ||
content: commentInfo[0].content | ||
}, | ||
reply: commentInfo[0].reply || null, | ||
authorDocument: commentInfo[0].author[0].email | ||
} | ||
// Send notification | ||
notification.sendEmail(type, emailProps) | ||
res.status(OK).json({ | ||
message: 'Email scheduled' | ||
}) | ||
} catch (err) { | ||
res.status(INTERNAL_SERVER_ERROR).json({ | ||
message: 'An error ocurred trying to schedule the email.', | ||
reason: err.message | ||
}) | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const express = require('express') | ||
const router = express.Router() | ||
const CommentNew = require('../controllers/comment-new') | ||
|
||
router.post('/', CommentNew.post) | ||
|
||
module.exports = router |
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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}> | ||
Hay un nuevo comentario en el proyecto <b>{props.document.title}</b> en <A href={`${ORGANIZATION_URL}/propuesta?id=${props.document.id.toString()}`}>{ORGANIZATION_NAME}</A> | ||
</Span> | ||
</Item> | ||
<Item style={Style.itemStyle}> | ||
<Span {...Style.defaultContentStyle}> | ||
Este fue el comentario: | ||
</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> | ||
</div> | ||
</div> | ||
</Item> | ||
</Box> | ||
</A> | ||
</Item> | ||
</Content> | ||
<MailFooter /> | ||
</Email> | ||
) | ||
} | ||
|
||
module.exports = (props) => renderEmail(<CommentRead {...props} />) |
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