Skip to content
Snippets Groups Projects
Commit 4a530562 authored by Sebastian Mihalache's avatar Sebastian Mihalache :hammer_pick:
Browse files

fix(recommendationsEmails): fix conflicts

parents 1590e6d2 49c68a42
No related branches found
No related tags found
1 merge request!115Hin 1038
const config = require('config') const config = require('config')
const { get, isEmpty, chain } = require('lodash') const { get, isEmpty, chain } = require('lodash')
const Email = require('@pubsweet/component-email-templating') const Email = require('@pubsweet/component-email-templating')
const unsubscribeSlug = config.get('unsubscribe.url')
const { getEmailCopy } = require('./emailCopy')
const { const {
User, User,
services, services,
Fragment, Fragment,
Collection,
} = require('pubsweet-component-helper-service') } = require('pubsweet-component-helper-service')
// const { getEmailCopy } = require('./emailCopy')
const helpers = require('./helpers') const helpers = require('./helpers')
const { getEmailCopy } = require('./emailCopy')
// const editorialAssistantEmail = config.get('journal.staffEmail')
const { name: journalName, staffEmail } = config.get('journal') const { name: journalName, staffEmail } = config.get('journal')
const unsubscribeSlug = config.get('unsubscribe.url')
class Notification { class Notification {
constructor({ constructor({
...@@ -472,7 +469,79 @@ class Notification { ...@@ -472,7 +469,79 @@ class Notification {
pendingReviewers.forEach(buildSendEmailFunction(pendingReviewersEmailBody)) 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() { async getNotificationProperties() {
const fragmentHelper = new Fragment({ fragment: this.fragment }) const fragmentHelper = new Fragment({ fragment: this.fragment })
......
...@@ -171,12 +171,14 @@ module.exports = models => async (req, res) => { ...@@ -171,12 +171,14 @@ module.exports = models => async (req, res) => {
notification.notifyAuthorsWhenEiCMakesDecision() notification.notifyAuthorsWhenEiCMakesDecision()
} }
} else { } else {
if (hasPeerReview) {
notification.notifyReviewersWhenHEMakesRecommendation()
}
if (collection.status === 'revisionRequested') { if (collection.status === 'revisionRequested') {
notification.notifySAWhenHERequestsRevision() notification.notifySAWhenHERequestsRevision()
} }
if (hasPeerReview) {
notification.notifyReviewersWhenHEMakesRecommendation()
notification.notifyEiCWhenHEMakesRecommendation()
}
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment