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 84fe7e375ac00bcbc6c2451c405200fd9ba744f2..039308228bfe2c1453c1e9ada3856ca86869d2b2 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notification.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notification.js @@ -1,21 +1,18 @@ const config = require('config') const { get, isEmpty, chain } = require('lodash') const Email = require('@pubsweet/component-email-templating') - -const unsubscribeSlug = config.get('unsubscribe.url') -const { getEmailCopy } = require('./emailCopy') - const { User, services, Fragment, + Collection, } = require('pubsweet-component-helper-service') -// const { getEmailCopy } = require('./emailCopy') const helpers = require('./helpers') +const { getEmailCopy } = require('./emailCopy') -// const editorialAssistantEmail = config.get('journal.staffEmail') const { name: journalName, staffEmail } = config.get('journal') +const unsubscribeSlug = config.get('unsubscribe.url') class Notification { constructor({ @@ -472,7 +469,79 @@ class Notification { pendingReviewers.forEach(buildSendEmailFunction(pendingReviewersEmailBody)) } - notifyEiCWhenHEMakesRecommendation() {} + async notifyEiCWhenHEMakesRecommendation() { + const { + eicName, + titleText, + recommendation, + } = await this.getNotificationProperties() + + let emailType, subject + switch (recommendation) { + case 'minor': + case 'major': + emailType = 'eic-request-revision-from-he' + subject = `${this.collection.customId}: Revision requested` + break + case 'publish': + emailType = 'eic-recommend-to-publish-from-he' + subject = `${this.collection.customId}: Recommendation to publish` + break + case 'reject': + emailType = 'eic-recommend-to-reject-from-he' + subject = `${this.collection.customId}: Recommendation to reject` + break + default: + throw new Error(`undefined recommendation: ${recommendation} `) + } + + const privateNote = this.newRecommendation.comments.find( + comm => !comm.public, + ) + const content = get(privateNote, 'content') + const comments = content + ? `The editor provided the following comments: "${content}"` + : '' + + const collHelper = new Collection({ collection: this.collection }) + const targetUserName = collHelper.getHELastName() + + const userHelper = new User({ UserModel: this.UserModel }) + const editors = await userHelper.getEditorsInChief() + + const emailBodyProps = getEmailCopy({ + comments, + emailType, + titleText, + targetUserName, + }) + + editors.forEach(eic => { + const email = new Email({ + type: 'user', + toUser: { + email: eic.email, + name: `${eic.firstName} ${eic.lastName}`, + }, + fromEmail: `${journalName} <${staffEmail}>`, + content: { + signatureName: eicName, + subject, + ctaText: 'MANUSCRIPT DETAILS', + unsubscribeLink: this.baseUrl, + ctaLink: services.createUrl( + this.baseUrl, + `/projects/${this.collection.id}/versions/${ + this.fragment.id + }/details`, + ), + }, + }) + + const { html, text } = email.getNotificationBody({ emailBodyProps }) + email.sendEmail({ html, text }) + }) + } async getNotificationProperties() { const fragmentHelper = new Fragment({ fragment: this.fragment }) diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js index 138fa0862c59d38e6d18c1c7d37405bcbe16144e..deca64d012c8853d4e36a39b8714e35c2013107f 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js @@ -171,12 +171,14 @@ module.exports = models => async (req, res) => { notification.notifyAuthorsWhenEiCMakesDecision() } } else { - if (hasPeerReview) { - notification.notifyReviewersWhenHEMakesRecommendation() - } if (collection.status === 'revisionRequested') { notification.notifySAWhenHERequestsRevision() } + + if (hasPeerReview) { + notification.notifyReviewersWhenHEMakesRecommendation() + notification.notifyEiCWhenHEMakesRecommendation() + } } }