Skip to content

Commit

Permalink
chore(Notifications)Unsubscibe-Notifications-
Browse files Browse the repository at this point in the history
Add route to email to unsubscribe from email notification
  • Loading branch information
Peace Oyedeji authored and Peace Oyedeji committed Mar 19, 2019
1 parent 6d1393b commit 47e537b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion server/api/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ export const deleteUser = async ({ user: { role }, params: { id } }, res) => {
}
};

export const unsubscribeMail = async ({ user: { id } }, res) => {
export const unsubscribeMail = async ({ params: { id } }, res) => {
try {
await User.update(
{ notifications: false },
Expand Down
8 changes: 4 additions & 4 deletions server/api/helpers/mailer/templates/articleGotNewComment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default ({
firstname, id, title, commenter, commentBody
firstname, id, title, commenter, commentBody, userId
}) => `
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
Expand Down Expand Up @@ -101,12 +101,12 @@ export default ({
<td height="10">&nbsp;</td>
</tr>
<tr>
<td valign="top" align="center"> <span style="font-family: -apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,&#39;Roboto&#39;,&#39;Oxygen&#39;,&#39;Ubuntu&#39;,&#39;Cantarell&#39;,&#39;Fira Sans&#39;,&#39;Droid Sans&#39;,&#39;Helvetica Neue&#39;,sans-serif; color:#9EB0C9; font-size:10px;">&copy;
<td valign="top" align="center"> <span style="font-family: -apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,&#39;Roboto&#39;,&#39;Oxygen&#39;,&#39;Ubuntu&#39;,&#39;Cantarell&#39;,&#39;Fira Sans&#39;,&#39;Droid Sans&#39;,&#39;Helvetica Neue&#39;,sans-serif; color:#9EB0C9; font-size:12px;">&copy;
<a href="#" target="_blank" style="color:#9EB0C9 !important; text-decoration:none;">Author's
Haven</a>
&nbsp;&nbsp;|&nbsp;&nbsp;
<a href="https://reallygoodemails.com/" target="_blank" style="color:#9EB0C9 !important; text-decoration:none;">Courtesy
of Really Good Emails</a>
<a href=${process.env.REACT_ENDPOINT}/api/users/${userId}/unsubscribe style="color:#9EB0C9 !important;">Unsubscribe
</a>from all future emails.
</span>
</td>
</tr>
Expand Down
8 changes: 4 additions & 4 deletions server/api/helpers/mailer/templates/newArticleTemplate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default ({
firstname, author, id, title
firstname, author, id, title, userId
}) => `
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
Expand Down Expand Up @@ -100,12 +100,12 @@ export default ({
<td height="10">&nbsp;</td>
</tr>
<tr>
<td valign="top" align="center"> <span style="font-family: -apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,&#39;Roboto&#39;,&#39;Oxygen&#39;,&#39;Ubuntu&#39;,&#39;Cantarell&#39;,&#39;Fira Sans&#39;,&#39;Droid Sans&#39;,&#39;Helvetica Neue&#39;,sans-serif; color:#9EB0C9; font-size:10px;">&copy;
<td valign="top" align="center"> <span style="font-family: -apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,&#39;Roboto&#39;,&#39;Oxygen&#39;,&#39;Ubuntu&#39;,&#39;Cantarell&#39;,&#39;Fira Sans&#39;,&#39;Droid Sans&#39;,&#39;Helvetica Neue&#39;,sans-serif; color:#9EB0C9; font-size:12px;">&copy;
<a href="#" target="_blank" style="color:#9EB0C9 !important; text-decoration:none;">Author's
Haven</a>
&nbsp;&nbsp;|&nbsp;&nbsp;
<a href="https://reallygoodemails.com/" target="_blank" style="color:#9EB0C9 !important; text-decoration:none;">Courtesy
of Really Good Emails</a>
<a href=${process.env.REACT_ENDPOINT}/api/users/${userId}/unsubscribe style="color:#9EB0C9 !important;">Unsubscribe
</a>from all future emails.
</span>
</td>
</tr>
Expand Down
7 changes: 3 additions & 4 deletions server/api/helpers/notification/bookmarkers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ export default async (articleId, commentBody, commenterId) => {
const info = {
commenter, commentBody, articleId, title
};

bookmarks.forEach(async ({ userId }) => {
const { firstname, email } = await User.findByPk(userId);
articleGotNewComment({ ...info, firstname }, email);
bookmarks.forEach(async ({ userId: id }) => {
const { firstname, email, id: userId } = await User.findByPk(id);
articleGotNewComment({ ...info, firstname, userId }, email);
});
};
8 changes: 5 additions & 3 deletions server/api/helpers/notification/followers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { newArticleMail } from '../mailer/mailer';
export default async (authorId, id, title) => {
const authorObj = await User.findByPk(authorId);
const followers = await authorObj.getFollowers({
attributes: ['email', 'firstname', 'notifications']
attributes: ['email', 'firstname', 'id', 'notifications']
});

const info = { author: `${authorObj.firstname}`, id, title };
followers.forEach(async ({ firstname, email, notifications }) => {
if (notifications) await newArticleMail({ ...info, firstname }, email);
followers.forEach(async ({
firstname, id: userId, email, notifications
}) => {
if (notifications) await newArticleMail({ ...info, firstname, userId }, email);
});
};
2 changes: 1 addition & 1 deletion server/api/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ userRouter.get('/:userId/profile', getUserProfile);
userRouter.patch('/:userId/profile', passport.authenticate('jwt', { session: false }),
profileUpdateValidation, updateUserProfile);

userRouter.patch('/:id/unsubscribe', passport.authenticate('jwt', { session: false }), unsubscribeMail);
userRouter.patch('/:id/unsubscribe', unsubscribeMail);

export default userRouter;

0 comments on commit 47e537b

Please sign in to comment.