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

feat(manuscript-manager): send email on eqa comments§

parent 734a31e6
No related branches found
No related tags found
2 merge requests!34Sprint 17 features,!31Hin 730
This commit is part of merge request !34. Comments created here will be created in the context of that merge request.
const uuid = require('uuid')
const { pick, get } = require('lodash')
const { pick, get, set } = require('lodash')
const config = require('config')
const { v4 } = require('uuid')
const {
services,
......@@ -90,6 +91,11 @@ module.exports = models => async (req, res) => {
}
await MTS.sendPackage({ fragment: packageFragment, isEQA: true })
collection.status = 'inQA'
set(collection, 'technicalChecks.token', v4())
set(collection, 'technicalChecks.hasEQA', false)
await collection.save()
}
notifications.sendNotifications({
......
const getEmailCopy = ({ emailType, titleText }) => {
const getEmailCopy = ({ emailType, titleText, comments }) => {
let paragraph
let hasLink = true
switch (emailType) {
......@@ -20,6 +20,10 @@ const getEmailCopy = ({ emailType, titleText }) => {
paragraph = `Thank you for your review on ${titleText}. After taking into account the reviews and the recommendation of the Handling Editor, I can confirm this article will now be published.<br/><br/>
If you have any queries about this decision, then please email them to Hindawi as soon as possible.`
break
case 'eqa-manuscript-returned-to-eic':
paragraph = `We regret to inform you that ${titleText} has been returned with comments. Please click the link below to access the manuscript.<br/><br/>
Comments: ${comments}<br/><br/>`
break
default:
throw new Error(`The ${emailType} email type is not defined.`)
}
......
......@@ -14,8 +14,10 @@ const unsubscribeSlug = config.get('unsubscribe.url')
module.exports = {
async sendNotifications({
isEQA,
agree,
baseUrl,
collection,
comments = '',
User: UserModel,
Fragment: FragmentModel,
}) {
......@@ -50,7 +52,7 @@ module.exports = {
},
})
if (isEQA) {
if (isEQA && agree) {
const eicName = await userHelper.getEiCName()
email.content.signatureName = eicName
sendAuthorsEmail({
......@@ -76,17 +78,28 @@ module.exports = {
subjectBaseText,
})
} else {
sendEditorsEmail({ email, userHelper, titleText })
sendEditorsEmail({ email, agree, comments, userHelper, titleText })
}
},
}
const sendEditorsEmail = async ({ email, userHelper, titleText }) => {
const sendEditorsEmail = async ({
email,
agree,
comments = '',
userHelper,
titleText,
}) => {
const emailType = agree
? 'eqs-manuscript-accepted'
: 'eqa-manuscript-returned-to-eic'
const editors = (await userHelper.getEditorsInChief()).map(eic => ({
...eic,
...getEmailCopy({
emailType: 'eqs-manuscript-accepted',
emailType,
titleText,
comments,
}),
}))
......
......@@ -18,7 +18,7 @@ const setNewStatus = (step, agree) => {
module.exports = ({ Collection, Fragment, User }) => async (req, res) => {
const { collectionId } = req.params
const { token, agree, step } = req.body
const { token, agree, step, comments } = req.body
try {
const collection = await Collection.find(collectionId)
......@@ -43,15 +43,15 @@ module.exports = ({ Collection, Fragment, User }) => async (req, res) => {
collection.status = setNewStatus(step, agree)
await collection.save()
if (agree) {
sendNotifications({
User,
Fragment,
collection,
baseUrl: services.getBaseUrl(req),
isEQA: step === TECHNICAL_STEPS.EQA,
})
}
sendNotifications({
User,
agree,
comments,
Fragment,
collection,
baseUrl: services.getBaseUrl(req),
isEQA: step === TECHNICAL_STEPS.EQA,
})
return res.status(200).json(collection)
} catch (e) {
......
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