Skip to content
Snippets Groups Projects
Commit 69862254 authored by Sebastian Mihalache's avatar Sebastian Mihalache
Browse files

feat(eic-role): send emails to multiple eics

parent 97b3ef8c
No related branches found
No related tags found
1 merge request!34Sprint 17 features
Showing
with 62 additions and 54 deletions
......@@ -11,7 +11,7 @@ const { getEmailCopy } = require('./emailCopy')
module.exports = {
async sendNotifications({ user, baseUrl, role, UserModel }) {
const userHelper = new User({ UserModel })
const { firstName, lastName } = await userHelper.getEditorInChief()
const { firstName, lastName } = await userHelper.getEditorsInChief()
const eicName = `${firstName} ${lastName}`
const email = new Email({
......
......@@ -41,12 +41,11 @@ class User {
return newUser
}
async getEditorInChief() {
async getEditorsInChief() {
const { UserModel } = this
const users = await UserModel.all()
const eic = users.find(user => user.editorInChief || user.admin)
return eic
return users.filter(user => user.editorInChief)
}
async updateUserTeams({ userId, teamId }) {
......@@ -65,6 +64,12 @@ class User {
return authors.filter(author => activeUsers.includes(author.id))
}
async getEiCName() {
const editorsInChief = await this.getEditorsInChief()
const { firstName, lastName } = editorsInChief[0]
return `${firstName} ${lastName}`
}
}
module.exports = User
......@@ -36,7 +36,8 @@ module.exports = {
} ${submittingAuthor.lastName}`
const userHelper = new User({ UserModel })
const eic = await userHelper.getEditorInChief()
const eics = await userHelper.getEditorsInChief()
const eic = eics[0]
const eicName = `${eic.firstName} ${eic.lastName}`
const subjectBaseText = `${collection.customId}: Manuscript `
......
......@@ -37,8 +37,7 @@ module.exports = {
const handlingEditor = get(collection, 'handlingEditor')
const userHelper = new User({ UserModel })
const { firstName, lastName } = await userHelper.getEditorInChief()
const eicName = `${firstName} ${lastName}`
const eicName = await userHelper.getEiCName()
const subjectBaseText = isCanceled
? `${collection.customId}: Reviewer `
: `${collection.customId}: Manuscript `
......
......@@ -49,9 +49,7 @@ module.exports = {
})
const userHelper = new User({ UserModel })
const eic = await userHelper.getEditorInChief()
const eicName = `${eic.firstName} ${eic.lastName}`
const eicName = await userHelper.getEiCName()
if (isNewVersion) {
sendHandlingEditorEmail({
email,
......@@ -76,8 +74,8 @@ module.exports = {
if (isTechnicalCheck) {
sendEQSEmail({
eic,
email,
eicName,
baseUrl,
collection,
subjectBaseText,
......@@ -157,7 +155,13 @@ const sendReviewersEmail = async ({
})
}
const sendEQSEmail = ({ eic, email, baseUrl, collection, subjectBaseText }) => {
const sendEQSEmail = ({
email,
eicName,
baseUrl,
collection,
subjectBaseText,
}) => {
const emailType = 'eqs-manuscript-submitted'
email.toUser = {
......@@ -166,7 +170,7 @@ const sendEQSEmail = ({ eic, email, baseUrl, collection, subjectBaseText }) => {
}
email.content.unsubscribeLink = baseUrl
email.content.signatureName = `${eic.firstName} ${eic.lastName}`
email.content.signatureName = eicName
email.content.subject = `${subjectBaseText} Submitted`
email.content.ctaLink = services.createUrl(
baseUrl,
......
......@@ -47,12 +47,6 @@ module.exports = {
})
const userHelper = new User({ UserModel })
const {
email: eicEmail,
firstName,
lastName,
} = await userHelper.getEditorInChief()
const eicName = `${firstName} ${lastName}`
let comments
if (isEditorInChief) {
......@@ -71,7 +65,7 @@ module.exports = {
// the request came from either the Editor in Chief or a reviewer, so the HE needs to be notified
sendHandlingEditorEmail({
email,
eicName,
eicName: await userHelper.getEiCName(),
baseUrl,
comments,
titleText,
......@@ -110,11 +104,10 @@ module.exports = {
handlingEditorName: get(collection, 'handlingEditor.name', 'N/A'),
})
sendEiCEmail({
sendEiCsEmail({
email,
baseUrl,
eicName,
eicEmail,
userHelper,
titleText,
subjectBaseText,
recommendation: newRecommendation,
......@@ -331,20 +324,18 @@ const sendReviewersEmail = async ({
},
)
const { html, text } = email.getBody({
body: { paragraph: reviewer.paragraph },
hasLink: reviewer.hasLink,
body: { paragraph: reviewer.paragraph, hasLink: reviewer.hasLink },
})
email.sendEmail({ html, text })
})
}
const sendEiCEmail = ({
const sendEiCsEmail = async ({
email,
eicName,
eicEmail,
titleText,
recommendation: { recommendation, comments: recComments = [] },
userHelper,
subjectBaseText,
recommendation: { recommendation, comments: recComments = [] },
}) => {
let emailType
......@@ -364,22 +355,29 @@ const sendEiCEmail = ({
throw new Error(`undefined recommendation: ${recommendation} `)
}
email.toUser = {
email: eicEmail,
name: eicName,
}
const privateNote = recComments.find(comm => comm.private)
const privateNote = recComments.find(comm => !comm.public)
const content = get(privateNote, 'content')
const comments = content ? `Note to Editor: "${content}"` : ''
const { html, text } = email.getBody({
body: getEmailCopy({
const editors = (await userHelper.getEditorsInChief()).map(eic => ({
...eic,
...getEmailCopy({
emailType,
titleText,
comments,
}),
}))
editors.forEach(eic => {
email.toUser = {
email: eic.email,
name: `${eic.firstName} ${eic.lastName}`,
}
const { html, text } = email.getBody({
body: { paragraph: eic.paragraph, hasLink: eic.hasLink },
})
email.sendEmail({ html, text })
})
email.sendEmail({ html, text })
}
const getSubjectByRecommendation = recommendation =>
......
......@@ -27,18 +27,9 @@ module.exports = {
} ${submittingAuthor.lastName}`
const userHelper = new User({ UserModel })
const {
lastName,
firstName,
email: eicEmail,
} = await userHelper.getEditorInChief()
const email = new Email({
type: 'user',
toUser: {
email: eicEmail,
name: `${firstName} ${lastName}`,
},
content: {
subject: `${collection.customId}: Manuscript Passed Technical Checks`,
signatureName: 'EQS Team',
......@@ -51,12 +42,23 @@ module.exports = {
},
})
const { html, text } = email.getBody({
body: getEmailCopy({
titleText,
const editors = (await userHelper.getEditorsInChief()).map(eic => ({
...eic,
...getEmailCopy({
emailType: 'eqs-manuscript-accepted',
titleText,
}),
}))
editors.forEach(eic => {
email.toUser = {
email: eic.email,
name: `${eic.firstName} ${eic.lastName}`,
}
const { html, text } = email.getBody({
body: { paragraph: eic.paragraph, hasLink: eic.hasLink },
})
email.sendEmail({ html, text })
})
email.sendEmail({ html, text })
},
}
......@@ -56,6 +56,7 @@ const createFilesPackage = (s3Config, archiver = nodeArchiver) => {
})
archive.on('error', err => {
logger.error(err)
throw err
})
archive.on('end', err => {
......
......@@ -33,8 +33,6 @@ module.exports = {
} ${submittingAuthor.lastName}`
const userHelper = new User({ UserModel })
const { firstName, lastName } = await userHelper.getEditorInChief()
const eicName = `${firstName} ${lastName}`
const subjectBaseText = `${collection.customId}: Manuscript`
const email = new Email({
......@@ -42,7 +40,7 @@ module.exports = {
content: {
ctaLink: baseUrl,
ctaText: 'VIEW DASHBOARD',
signatureName: eicName,
signatureName: await userHelper.getEiCName(),
},
})
......
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