Skip to content
Snippets Groups Projects
Commit b00786f4 authored by Andrei Cioromila's avatar Andrei Cioromila
Browse files

refactor(notifications): extract reviewer notification when eic makes decision

parent edd45dce
No related branches found
No related tags found
1 merge request!115Hin 1038
......@@ -180,17 +180,28 @@ class Notification {
parsedFragment,
} = await this.getNotificationProperties()
activeAuthors.forEach(async author => {
const subjectOpts = {
publish: `${this.collection.customId}: Manuscript accepted`,
reject: `${this.collection.customId}: Manuscript rejected`,
}
const subject = subjectOpts[recommendation]
const subjectOpts = {
publish: `${this.collection.customId}: Manuscript accepted`,
reject: `${this.collection.customId}: Manuscript rejected`,
}
const subject = subjectOpts[recommendation]
if (isEmpty(subject)) {
throw new Error(`Undefined recommendation: ${recommendation}`)
}
if (isEmpty(subject)) {
throw new Error(`Undefined recommendation: ${recommendation}`)
}
const hasPeerReview = !isEmpty(this.collection.handlingEditor)
const emailType = helpers.getEmailTypeByRecommendationForAuthors({
recommendation,
hasPeerReview,
})
const comments = hasPeerReview
? helpers.getHEComments({
heRecommendation: parsedFragment.heRecommendation,
})
: this.newRecommendation.comments[0].content
activeAuthors.forEach(async author => {
const email = new Email({
type: 'user',
toUser: {
......@@ -216,20 +227,6 @@ class Notification {
},
})
const hasPeerReview = !isEmpty(this.collection.handlingEditor)
const emailType = helpers.getEmailTypeByRecommendationForAuthors({
recommendation,
hasPeerReview,
})
let comments
if (hasPeerReview) {
comments = helpers.getHEComments({
heRecommendation: parsedFragment.heRecommendation,
})
} else {
comments = this.newRecommendation.comments[0].content
}
const { html, text } = email.getNotificationBody({
emailBodyProps: getEmailCopy({
titleText,
......@@ -237,11 +234,69 @@ class Notification {
comments,
}),
})
email.sendEmail({ html, text })
})
}
notifyReviewersWhenEiCMakesDecision() {}
async notifyReviewersWhenEiCMakesDecision() {
const {
eicName,
titleText,
recommendation,
fragmentHelper,
} = await this.getNotificationProperties()
const emailType =
recommendation === 'publish'
? 'submitted-reviewers-after-publish'
: 'submitted-reviewers-after-reject'
const subject =
recommendation === 'publish'
? 'A manuscript you reviewed has been accepted'
: 'A manuscript you reviewed has been rejected'
const reviewers = await fragmentHelper.getReviewers({
UserModel: this.UserModel,
type: 'submitted',
})
const emailBodyProps = getEmailCopy({
emailType,
titleText,
})
reviewers.forEach(reviewer => {
const email = new Email({
type: 'user',
toUser: {
email: reviewer.email,
name: reviewer.lastName,
},
fromEmail: `${eicName} <${staffEmail}>`,
content: {
signatureName: eicName,
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 })
})
}
notifySAWhenHERequestsRevision() {}
......@@ -278,6 +333,7 @@ class Notification {
submittingAuthor,
activeAuthors,
parsedFragment,
fragmentHelper,
}
}
}
......
......@@ -165,6 +165,8 @@ module.exports = models => async (req, res) => {
}
notification.notifyAuthorsWhenEiCMakesDecision()
notification.notifyReviewersWhenEiCMakesDecision()
}
} else {
// notifications.sendNotificationsWhenHEMakesRecommendation({
......
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