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

refactor(manuscript-manager): update fragment submission routes to use new email structure

parent 85dcd245
No related branches found
No related tags found
3 merge requests!160Update staging with master features,!156Develop,!149Hin 1089
......@@ -15,34 +15,29 @@ const unsubscribeSlug = config.get('unsubscribe.url')
const { getEmailCopy } = require('./emailCopy')
module.exports = {
async sendNotifications({
baseUrl,
fragment,
UserModel,
collection,
isNewVersion = false,
previousVersion,
isTechnicalCheck,
isMajorRecommendation,
}) {
async sendHandlingEditorEmail({ baseUrl, fragment, UserModel, collection }) {
const fragmentHelper = new Fragment({ fragment })
const handlingEditor = get(collection, 'handlingEditor')
const parsedFragment = await fragmentHelper.getFragmentData({
handlingEditor,
})
const {
submittingAuthor,
activeAuthors: authors,
} = await fragmentHelper.getAuthorData({
UserModel,
const { paragraph, ...bodyProps } = getEmailCopy({
emailType: 'he-new-version-submitted',
titleText: `the manuscript titled "${parsedFragment.title}"`,
})
const { customId } = collection
const heUser = await UserModel.find(handlingEditor.id)
const email = new Email({
type: 'user',
fromEmail: `${journalName} <${staffEmail}>`,
toUser: {
email: heUser.email,
},
content: {
subject: `${collection.customId}: Revision submitted`,
paragraph,
signatureName: '',
signatureJournal: journalName,
ctaLink: services.createUrl(
......@@ -50,240 +45,199 @@ module.exports = {
`/projects/${collection.id}/versions/${fragment.id}/details`,
),
ctaText: 'MANUSCRIPT DETAILS',
unsubscribeLink: services.createUrl(baseUrl, unsubscribeSlug, {
id: heUser.id,
token: heUser.accessTokens.unsubscribe,
}),
},
bodyProps,
})
const userHelper = new User({ UserModel })
const eicName = await userHelper.getEiCName()
if (isNewVersion) {
const heUser = await UserModel.find(handlingEditor.id)
sendHandlingEditorEmail({
email,
baseUrl,
customId,
title: parsedFragment.title,
handlingEditor: heUser,
})
}
if (isMajorRecommendation) {
sendReviewersEmail({
email,
baseUrl,
customId,
UserModel,
previousVersion,
title: parsedFragment.title,
heName: collection.handlingEditor.name,
})
}
if (isTechnicalCheck) {
sendEQSEmail({
email,
eicName,
baseUrl,
collection,
})
sendAuthorsEmail({
email,
baseUrl,
UserModel,
fragmentId: fragment.id,
fragmentAuthors: authors,
collectionId: collection.id,
title: parsedFragment.title,
submittingAuthorName: `${submittingAuthor.firstName} ${
submittingAuthor.lastName
}`,
})
}
email.sendEmail()
},
}
const sendHandlingEditorEmail = ({
email,
title,
baseUrl,
customId,
handlingEditor,
}) => {
const emailType = 'he-new-version-submitted'
email.toUser = {
email: handlingEditor.email,
}
email.content.unsubscribeLink = services.createUrl(baseUrl, unsubscribeSlug, {
id: handlingEditor.id,
token: handlingEditor.accessTokens.unsubscribe,
})
email.content.subject = `${customId}: Revision submitted`
const { html, text } = email.getNotificationBody({
emailBodyProps: getEmailCopy({
emailType,
titleText: `the manuscript titled "${title}"`,
}),
})
email.sendEmail({ html, text })
}
const sendReviewersEmail = async ({
email,
title,
heName,
baseUrl,
customId,
UserModel,
previousVersion,
}) => {
email.content.subject = `${customId}: A manuscript you reviewed has been revised`
email.content.signatureName = heName
email.fromEmail = `${heName} <${staffEmail}>`
const emailType = 'submitted-reviewers-after-revision'
const fragmentHelper = new Fragment({ fragment: previousVersion })
const reviewers = await fragmentHelper.getReviewers({
async sendReviewersEmail({
baseUrl,
fragment,
UserModel,
type: 'submitted',
})
reviewers.forEach(reviewer => {
email.toUser = {
email: reviewer.email,
name: `${reviewer.lastName}`,
}
collection,
previousVersion,
}) {
const fragmentHelper = new Fragment({ fragment: previousVersion })
const handlingEditor = get(collection, 'handlingEditor')
const parsedFragment = await fragmentHelper.getFragmentData({
handlingEditor,
})
email.content.unsubscribeLink = services.createUrl(
baseUrl,
unsubscribeSlug,
{
id: reviewer.id,
token: reviewer.accessTokens.unsubscribe,
},
)
const reviewers = await fragmentHelper.getReviewers({
UserModel,
type: 'submitted',
})
const { html, text } = email.getNotificationBody({
emailBodyProps: getEmailCopy({
emailType,
titleText: `the manuscript titled "${title}"`,
expectedDate: services.getExpectedDate({ daysExpected: 14 }),
}),
const { paragraph, ...bodyProps } = getEmailCopy({
emailType: 'submitted-reviewers-after-revision',
titleText: `the manuscript titled "${parsedFragment.title}"`,
expectedDate: services.getExpectedDate({ daysExpected: 14 }),
})
email.sendEmail({ html, text })
})
}
reviewers.forEach(reviewer => {
const email = new Email({
type: 'user',
fromEmail: `${handlingEditor.name} <${staffEmail}>`,
toUser: {
email: reviewer.email,
name: `${reviewer.lastName}`,
},
content: {
subject: `${
collection.customId
}: A manuscript you reviewed has been revised`,
paragraph,
signatureName: handlingEditor.name,
signatureJournal: journalName,
ctaLink: services.createUrl(
baseUrl,
`/projects/${collection.id}/versions/${fragment.id}/details`,
),
ctaText: 'MANUSCRIPT DETAILS',
unsubscribeLink: services.createUrl(baseUrl, unsubscribeSlug, {
id: reviewer.id,
token: reviewer.accessTokens.unsubscribe,
}),
},
bodyProps,
})
const sendEQSEmail = ({ email, eicName, baseUrl, collection }) => {
const emailType = 'eqs-manuscript-submitted'
email.sendEmail()
})
},
email.toUser = {
email: staffEmail,
name: 'Editorial Assistant',
}
async sendEQSEmail({ baseUrl, fragment, UserModel, collection }) {
const userHelper = new User({ UserModel })
const eicName = await userHelper.getEiCName()
email.content.unsubscribeLink = baseUrl
email.content.signatureName = eicName
email.content.subject = `Manuscript Submitted`
email.content.ctaLink = services.createUrl(
baseUrl,
config.get('eqs-decision.url'),
{
collectionId: collection.id,
const { paragraph, ...bodyProps } = getEmailCopy({
emailType: 'eqs-manuscript-submitted',
customId: collection.customId,
token: collection.technicalChecks.token,
},
)
email.content.ctaText = 'MAKE DECISION'
})
const { html, text } = email.getNotificationBody({
emailBodyProps: getEmailCopy({
emailType,
customId: collection.customId,
}),
})
email.sendEmail({ html, text })
}
const email = new Email({
type: 'user',
fromEmail: `${journalName} <${staffEmail}>`,
toUser: {
email: staffEmail,
name: 'Editorial Assistant',
},
content: {
subject: `Manuscript Submitted`,
paragraph,
signatureName: eicName,
signatureJournal: journalName,
ctaLink: services.createUrl(baseUrl, config.get('eqs-decision.url'), {
collectionId: collection.id,
customId: collection.customId,
token: collection.technicalChecks.token,
}),
ctaText: 'MAKE DECISION',
unsubscribeLink: baseUrl,
},
bodyProps,
})
const sendAuthorsEmail = async ({
email,
title,
baseUrl,
UserModel,
fragmentId,
collectionId,
fragmentAuthors,
submittingAuthorName,
}) => {
email.content.subject = `Manuscript submitted to ${journalName}`
email.content.signatureName = ''
email.sendEmail()
},
const userEmailData = await Promise.all(
fragmentAuthors.map(async author => {
const user = await UserModel.find(author.id)
return {
...author,
isConfirmed: user.isConfirmed,
unsubscribeToken: user.accessTokens.unsubscribe,
passwordResetToken: user.accessTokens.passwordReset,
...getEmailCopy({
async sendAuthorsEmail({ baseUrl, fragment, UserModel, collection }) {
const fragmentHelper = new Fragment({ fragment })
const handlingEditor = get(collection, 'handlingEditor')
const parsedFragment = await fragmentHelper.getFragmentData({
handlingEditor,
})
const {
submittingAuthor,
activeAuthors: fragmentAuthors,
} = await fragmentHelper.getAuthorData({
UserModel,
})
const submittingAuthorName = `${submittingAuthor.firstName} ${
submittingAuthor.lastName
}`
const userEmailData = await Promise.all(
fragmentAuthors.map(async author => {
const { paragraph, ...bodyProps } = getEmailCopy({
emailType: author.isSubmitting
? 'submitting-author-manuscript-submitted'
: 'coauthors-manuscript-submitted',
titleText: author.isSubmitting
? `the manuscript titled "${title}"`
: `The manuscript titled "${title}" has been submitted to ${journalName} by ${submittingAuthorName}`,
}),
}
}),
)
userEmailData.forEach(author => {
email.toUser = {
email: author.email,
name: `${author.lastName}`,
}
email.content.unsubscribeLink = services.createUrl(
baseUrl,
unsubscribeSlug,
{
id: author.id,
token: author.unsubscribeToken,
},
? `the manuscript titled "${parsedFragment.title}"`
: `The manuscript titled "${
parsedFragment.title
}" has been submitted to ${journalName} by ${submittingAuthorName}`,
})
const user = await UserModel.find(author.id)
return {
author: Object.assign(author, {
isConfirmed: user.isConfirmed,
unsubscribeToken: user.accessTokens.unsubscribe,
passwordResetToken: user.accessTokens.passwordReset,
}),
paragraph,
bodyProps,
}
}),
)
if (author.isSubmitting) {
email.content.ctaLink = services.createUrl(
baseUrl,
`/projects/${collectionId}/versions/${fragmentId}/details`,
)
email.content.ctaText = 'MANUSCRIPT DETAILS'
} else if (author.isConfirmed) {
email.content.ctaLink = services.createUrl(baseUrl, '')
email.content.ctaText = 'LOG IN'
} else {
email.content.ctaLink = services.createUrl(baseUrl, resetPath, {
email: author.email,
token: author.passwordResetToken,
firstName: author.firstName,
lastName: author.lastName,
affiliation: author.affiliation,
title: author.title,
country: author.country,
userEmailData.forEach(({ author, paragraph, bodyProps }) => {
const email = new Email({
type: 'user',
fromEmail: `${journalName} <${staffEmail}>`,
toUser: {
email: author.email,
name: `${author.lastName}`,
},
content: {
subject: `Manuscript submitted to ${journalName}`,
paragraph,
signatureName: '',
signatureJournal: journalName,
ctaLink: services.createUrl(
baseUrl,
`/projects/${collection.id}/versions/${fragment.id}/details`,
),
ctaText: 'MANUSCRIPT DETAILS',
unsubscribeLink: services.createUrl(baseUrl, unsubscribeSlug, {
id: author.id,
token: author.unsubscribeToken,
}),
},
bodyProps,
})
email.content.ctaText = 'CONFIRM ACCOUNT'
}
const { html, text } = email.getNotificationBody({
emailBodyProps: {
paragraph: author.paragraph,
hasLink: author.hasLink,
hasIntro: author.hasIntro,
hasSignature: author.hasSignature,
},
if (author.isSubmitting) {
email.content.ctaLink = services.createUrl(
baseUrl,
`/projects/${collection.id}/versions/${fragment.id}/details`,
)
email.content.ctaText = 'MANUSCRIPT DETAILS'
} else if (author.isConfirmed) {
email.content.ctaLink = services.createUrl(baseUrl, '')
email.content.ctaText = 'LOG IN'
} else {
email.content.ctaLink = services.createUrl(baseUrl, resetPath, {
email: author.email,
token: author.passwordResetToken,
firstName: author.firstName,
lastName: author.lastName,
affiliation: author.affiliation,
title: author.title,
country: author.country,
})
email.content.ctaText = 'CONFIRM ACCOUNT'
}
email.sendEmail()
})
email.sendEmail({ html, text })
})
},
}
......@@ -112,16 +112,23 @@ module.exports = models => async (req, res) => {
collection.fragments.push(newFragment.id)
collection.save()
notifications.sendNotifications({
collection,
isNewVersion: true,
notifications.sendHandlingEditorEmail({
baseUrl: services.getBaseUrl(req),
fragment: newFragment,
UserModel: models.User,
previousVersion: fragment,
baseUrl: services.getBaseUrl(req),
isMajorRecommendation: heRecommendation.recommendation === 'major',
collection,
})
if (heRecommendation.recommendation === 'major') {
notifications.sendReviewersEmail({
baseUrl: services.getBaseUrl(req),
fragment: newFragment,
UserModel: models.User,
collection,
previousVersion: fragment,
})
}
return res.status(200).json(newFragment)
} catch (e) {
const notFoundError = await services.handleNotFoundError(e, 'Item')
......
......@@ -62,11 +62,17 @@ module.exports = models => async (req, res) => {
await sendMTSPackage(collection, fragment)
}
notifications.sendNotifications({
notifications.sendEQSEmail({
fragment,
collection,
UserModel: models.User,
baseUrl: services.getBaseUrl(req),
})
notifications.sendAuthorsEmail({
fragment,
collection,
UserModel: models.User,
isTechnicalCheck: true,
baseUrl: services.getBaseUrl(req),
})
......
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