diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notification.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notification.js index cee8456e28c67af7e13d2265e85d748303097553..593f705d6240cb64cfb128a4b0bbfe37c00a6ad8 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notification.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notification.js @@ -360,7 +360,73 @@ class Notification { email.sendEmail({ html, text }) } - notifyReviewersWhenHEMakesRecommendation() {} + async notifyReviewersWhenHEMakesRecommendation() { + const { + eicName, + titleText, + recommendation, + fragmentHelper, + } = await this.getNotificationProperties() + + const signatureName = get(this.collection, 'handlingEditor.name', eicName) + const subject = + recommendation === 'publish' + ? 'A manuscript you reviewed has been accepted' + : 'A manuscript you reviewed has been rejected' + + const acceptedReviewers = await fragmentHelper.getReviewers({ + UserModel: this.UserModel, + type: 'accepted', + }) + const acceptedReviewersEmailBody = getEmailCopy({ + emailType: 'accepted-reviewers-after-recommendation', + titleText, + }) + + const pendingReviewers = await fragmentHelper.getReviewers({ + UserModel: this.UserModel, + type: 'pending', + }) + const pendingReviewersEmailBody = getEmailCopy({ + emailType: 'pending-reviewers-after-recommendation', + titleText, + }) + + const buildSendEmailFunction = emailBodyProps => reviewer => { + const email = new Email({ + type: 'user', + toUser: { + email: reviewer.email, + name: reviewer.lastName, + }, + fromEmail: `${eicName} <${staffEmail}>`, + content: { + signatureName, + ctaText: 'MANUSCRIPT DETAILS', + subject: `${this.collection.customId}: ${subject}`, + unsubscribeLink: services.createUrl(this.baseUrl, unsubscribeSlug, { + id: reviewer.id, + token: reviewer.accessTokens.unsubscribe, + }), + ctaLink: services.createUrl( + this.baseUrl, + `/projects/${this.collection.id}/versions/${ + this.fragment.id + }/details`, + ), + signatureJournal: journalName, + }, + }) + + const { html, text } = email.getNotificationBody({ emailBodyProps }) + email.sendEmail({ html, text }) + } + + acceptedReviewers.forEach( + buildSendEmailFunction(acceptedReviewersEmailBody), + ) + pendingReviewers.forEach(buildSendEmailFunction(pendingReviewersEmailBody)) + } notifyEiCWhenHEMakesRecommendation() {} diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js index e281edf6af99274d70572c313fd48980252efc8e..1afb4a42c511e3cedd40dd089e443f1a600c48aa 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js @@ -1,5 +1,5 @@ const uuid = require('uuid') -const { pick, get, set, has } = require('lodash') +const { pick, get, set, has, isEmpty } = require('lodash') const config = require('config') const { v4 } = require('uuid') @@ -135,6 +135,14 @@ module.exports = models => async (req, res) => { await collection.save() } + const notification = new Notification({ + fragment, + collection, + newRecommendation, + UserModel: models.User, + baseUrl: services.getBaseUrl(req), + }) + if (isEditorInChief) { // notifications.sendNotificationsWhenEiCMakesDecision({ // hasEQA, @@ -145,13 +153,6 @@ module.exports = models => async (req, res) => { // targetUserName: reqUser.lastName, // baseUrl: services.getBaseUrl(req), // }) - const notification = new Notification({ - fragment, - collection, - newRecommendation, - UserModel: models.User, - baseUrl: services.getBaseUrl(req), - }) if ( recommendation === 'publish' && @@ -169,6 +170,12 @@ module.exports = models => async (req, res) => { notification.notifyReviewersWhenEiCMakesDecision() } } else { + notification.notifySAWhenHERequestsRevision() + + const hasPeerReview = !isEmpty(collection.handlingEditor) + if (hasPeerReview) { + notification.notifyReviewersWhenHEMakesRecommendation() + } // notifications.sendNotificationsWhenHEMakesRecommendation({ // fragment, // collection,