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