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

refactor(notifications): extract he notification when reviewer submits report

parent 1dff80d2
No related branches found
No related tags found
1 merge request!115Hin 1038
......@@ -13,7 +13,6 @@ const {
// const { getEmailCopy } = require('./emailCopy')
const helpers = require('./helpers')
const reviewHelpers = require('./reviewerSubmitsReport/helpers')
// const editorialAssistantEmail = config.get('journal.staffEmail')
const { name: journalName, staffEmail } = config.get('journal')
......@@ -43,28 +42,25 @@ class Notification {
}
async notifyHEWhenReviewerSubmitsReport(reviewerLastName) {
const { eicName, titleText } = this.properties
const { eicName, titleText } = await this.properties
const { collection } = this
const handlingEditor = get(collection, 'handlingEditor', {})
const { customId } = collection
const collHelper = new Collection({ collection })
const handlingEditorId = get(this.collection, 'handlingEditor.id')
const heUser = await this.UserModel.find(handlingEditorId)
const email = new Email({
type: 'user',
toUser: {
email: handlingEditor.email,
name: collHelper.getHELastName(),
email: heUser.email,
name: heUser.lastName,
},
fromEmail: `${eicName} <${staffEmail}>`,
content: {
signatureName: eicName,
ctaText: 'MANUSCRIPT DETAILS',
subject: `${customId}: A review has been submitted`,
subject: `${this.collection.customId}: A review has been submitted`,
unsubscribeLink: services.createUrl(this.baseUrl, unsubscribeSlug, {
id: handlingEditor.id,
token: handlingEditor.accessTokens.unsubscribe,
id: heUser.id,
token: heUser.accessTokens.unsubscribe,
}),
ctaLink: services.createUrl(
this.baseUrl,
......@@ -92,13 +88,16 @@ class Notification {
UserModel: this.UserModel,
})
const userHelper = new User({ UserModel: this.UserModel })
const eicName = await userHelper.getEiCName()
const titleText = `the manuscript titled "${parsedFragment.title}" by ${
submittingAuthor.firstName
} ${submittingAuthor.lastName}`
const { recommendation, recommendationType } = this.newRecommendation
return { recommendation, recommendationType, titleText }
return { recommendation, recommendationType, eicName, titleText }
}
}
......
......@@ -42,7 +42,7 @@ module.exports = models => async (req, res) => {
})
const UserModel = models.User
const user = await UserModel.find(req.user)
const reviewer = await UserModel.find(req.user)
Object.assign(recommendation, req.body)
recommendation.updatedOn = Date.now()
......@@ -56,7 +56,7 @@ module.exports = models => async (req, res) => {
newRecommendation: recommendation,
})
notification.notifyHEWhenReviewerSubmitsReport(`${user.lastName}`)
notification.notifyHEWhenReviewerSubmitsReport(reviewer.lastName)
if (['underReview'].includes(collection.status)) {
const collectionHelper = new Collection({ collection })
......
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