From 49c68a42a78f7b49785ae3cdef1a837424379a41 Mon Sep 17 00:00:00 2001 From: Andrei Cioromila <andrei.cioromila@thinslices.com> Date: Tue, 23 Oct 2018 12:21:53 +0300 Subject: [PATCH] refactor(notifications): extract eic notification when he makes recommendation --- .../notifications/notification.js | 74 ++++++++++++++++++- .../routes/fragmentsRecommendations/post.js | 8 +- 2 files changed, 78 insertions(+), 4 deletions(-) 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 961d23b9e..46e33269f 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notification.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notification.js @@ -423,7 +423,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 1c1f531ad..8f0f82cc8 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js @@ -170,12 +170,14 @@ module.exports = models => async (req, res) => { notification.notifyReviewersWhenEiCMakesDecision() } } else { + if (collection.status === 'revisionRequested') { + notification.notifySAWhenHERequestsRevision() + } + const hasPeerReview = !isEmpty(collection.handlingEditor) if (hasPeerReview) { notification.notifyReviewersWhenHEMakesRecommendation() - } - if (collection.status === 'revisionRequested') { - notification.notifySAWhenHERequestsRevision() + notification.notifyEiCWhenHEMakesRecommendation() } } } -- GitLab