diff --git a/packages/component-email/src/routes/emails/notifications.js b/packages/component-email/src/routes/emails/notifications.js index 23fea64c842350cd283d72b55f58c1b86a920d95..e5783fd5e02ea2586a854a7836fb2096495c2fb0 100644 --- a/packages/component-email/src/routes/emails/notifications.js +++ b/packages/component-email/src/routes/emails/notifications.js @@ -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({ diff --git a/packages/component-helper-service/src/services/User.js b/packages/component-helper-service/src/services/User.js index 074414d59f43dcf979d912244249fce897b7d7b7..2eb092ceeb1220254e93270c9ef2f8dc2876f182 100644 --- a/packages/component-helper-service/src/services/User.js +++ b/packages/component-helper-service/src/services/User.js @@ -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 diff --git a/packages/component-invite/src/routes/collectionsInvitations/emails/notifications.js b/packages/component-invite/src/routes/collectionsInvitations/emails/notifications.js index 44c00f6856cbb40b92f735a8744df41ce73532b7..90df1a7ce364a2445dd79238dd9f4837392be5c8 100644 --- a/packages/component-invite/src/routes/collectionsInvitations/emails/notifications.js +++ b/packages/component-invite/src/routes/collectionsInvitations/emails/notifications.js @@ -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 ` diff --git a/packages/component-invite/src/routes/fragmentsInvitations/emails/notifications.js b/packages/component-invite/src/routes/fragmentsInvitations/emails/notifications.js index 12cad6a9d5283e486784a5a08c037b1b4c23d669..9eeb709b629ee52e0ab63624c4a25019b1dc1a95 100644 --- a/packages/component-invite/src/routes/fragmentsInvitations/emails/notifications.js +++ b/packages/component-invite/src/routes/fragmentsInvitations/emails/notifications.js @@ -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 ` diff --git a/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js b/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js index 012113ffdbbd6df5542523b231860bdacaab7032..ee0f6f2918511fe268a35a1b9bca28c6e8d9e4c9 100644 --- a/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js +++ b/packages/component-manuscript-manager/src/routes/fragments/notifications/notifications.js @@ -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, diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js index 97195facf3ae5c2bef3e109409784d6696d3cb36..b318595833c0efbf0f46f5b9ff37ad292b504677 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/notifications/notifications.js @@ -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 => diff --git a/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js b/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js index 0da35cdfd11321ba4fbced245cd01a8e8a9ba22f..782cdbb0c0325048800a2f12096f013319fd8b8f 100644 --- a/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js +++ b/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js @@ -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 }) }, } diff --git a/packages/component-mts-package/src/PackageManager.js b/packages/component-mts-package/src/PackageManager.js index 2bbed4fbd45321d05fa6f07d437e36aad552d7fd..967985f3a45c6170fbd6a4b5d2d627ebe8cac633 100644 --- a/packages/component-mts-package/src/PackageManager.js +++ b/packages/component-mts-package/src/PackageManager.js @@ -56,6 +56,7 @@ const createFilesPackage = (s3Config, archiver = nodeArchiver) => { }) archive.on('error', err => { + logger.error(err) throw err }) archive.on('end', err => { diff --git a/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js b/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js index 8ee396d5206c25e20e52c5145938a8242cbde576..413ea4967f01a4244415681d2505edc1f7847618 100644 --- a/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js +++ b/packages/component-user-manager/src/routes/fragmentsUsers/emails/notifications.js @@ -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(), }, })