From 1658f7e350df4fca293d207d299ddb2f4213cb9e Mon Sep 17 00:00:00 2001 From: Sebastian Mihalache <sebastian.mihalache@gmail.con> Date: Thu, 9 Aug 2018 16:15:23 +0300 Subject: [PATCH] =?UTF-8?q?feat(manuscript-manager):=20send=20email=20on?= =?UTF-8?q?=20eqa=20comments=C2=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routes/fragmentsRecommendations/post.js | 8 ++++++- .../notifications/emailCopy.js | 6 +++++- .../notifications/notifications.js | 21 +++++++++++++++---- .../src/routes/technicalChecks/patch.js | 20 +++++++++--------- 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js index 5ee90e91e..37010631d 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js @@ -1,6 +1,7 @@ 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({ diff --git a/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/emailCopy.js b/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/emailCopy.js index 6d8160a84..0c36acca5 100644 --- a/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/emailCopy.js +++ b/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/emailCopy.js @@ -1,4 +1,4 @@ -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.`) } 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 c097ac541..5102aff7e 100644 --- a/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js +++ b/packages/component-manuscript-manager/src/routes/technicalChecks/notifications/notifications.js @@ -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, }), })) diff --git a/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js b/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js index f959d3809..3e6061fd3 100644 --- a/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js +++ b/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js @@ -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) { -- GitLab