Skip to content

Commit

Permalink
feat: Enable sending notifications for new project versions or commen…
Browse files Browse the repository at this point in the history
…ts notifications

The `SEND_NOTIFICATIONS` environment variable is now used to control whether notifications should be sent for new project versions or comments notifications. If the variable is set to `true`, notifications will be sent. If it is set to `false`, notifications will be skipped.
  • Loading branch information
guillecro committed May 20, 2024
1 parent a607dc6 commit cf64fa5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ APP_URL=http://localhost:4000 # For multiple domains, separate them with comma
MONGODB_URL=mongodb://localhost:27017/ac_dev
JWT_SECRET=THisIsMySecretKey! # For production, set to a long random string
PORT=3000
SEND_NOTIFICATIONS=true
MAILER_FROM="My Org APP <[email protected]>"
MAILER_HOST=sandbox.smtp.mailtrap.io
MAILER_PORT=2525
Expand Down
2 changes: 1 addition & 1 deletion controllers/projectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ exports.createVersion = async (req, res) => {
await project.save()

// send notification of new version
await ProjectHelper.notifyUsersNewVersion(project._id);
await ProjectHelper.sendNotificationNewProjectVersion(project._id);

// return
return res.status(200).json(project);
Expand Down
15 changes: 15 additions & 0 deletions helpers/commentHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const agenda = require('../services/agenda');

exports.sendNotificationCommentResolved = async (commentId) => {
try {
if(process.env.SEND_NOTIFICATIONS === 'false') {
console.log('Notifications are disabled, skipping email');
return;
}

const comment = await Comment.findById(commentId).populate({
path: 'project',
select: '_id title_es title_pt slug'
Expand Down Expand Up @@ -61,6 +66,11 @@ exports.sendNotificationCommentResolved = async (commentId) => {

exports.sendNotificationCommentHighlighted = async (commentId) => {
try {
if(process.env.SEND_NOTIFICATIONS === 'false') {
console.log('Notifications are disabled, skipping email');
return;
}

const comment = await Comment.findById(commentId).populate({
path: 'project',
select: '_id title_es title_pt slug'
Expand Down Expand Up @@ -117,6 +127,11 @@ exports.sendNotificationCommentHighlighted = async (commentId) => {

exports.sendNotificationCommentReplied = async (commentId, replyId) => {
try {
if(process.env.SEND_NOTIFICATIONS === 'false') {
console.log('Notifications are disabled, skipping email');
return;
}

const comment = await Comment.findById(commentId).populate({
path: 'project',
select: '_id title_es title_pt slug'
Expand Down
7 changes: 6 additions & 1 deletion helpers/projectsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,13 @@ exports.getProjectCurrentStats = async (projectId) => {
}
}

exports.notifyUsersNewVersion = async (projectId) => {
exports.sendNotificationNewProjectVersion = async (projectId) => {
try {
if(process.env.SEND_NOTIFICATIONS === 'false') {
console.log('Notifications are disabled, skipping email');
return;
}

const project = await Project.findById(projectId).populate({
path: 'author',
select: '_id name email lang',
Expand Down

0 comments on commit cf64fa5

Please sign in to comment.