From 8d580f8b784c10d9f5dd4a4bf6089578b1d82b76 Mon Sep 17 00:00:00 2001
From: Sebastian Mihalache <sebi.mihalache@gmail.com>
Date: Thu, 25 Oct 2018 13:20:43 +0300
Subject: [PATCH] fix(recommendationsEmails): EQA emails logic

---
 .../src/routes/fragmentsRecommendations/post.js  | 16 ++++++----------
 .../src/routes/technicalChecks/patch.js          |  2 +-
 2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js
index 32ea418b7..fc2f8ec70 100644
--- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js
+++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js
@@ -145,16 +145,12 @@ module.exports = models => async (req, res) => {
     const hasPeerReview = !isEmpty(collection.handlingEditor)
 
     if (isEditorInChief) {
-      if (
-        recommendation === 'publish' &&
-        collection.technicalChecks.token &&
-        ['accepted', 'inQA'].includes(collection.status)
-      ) {
-        if (collection.status === 'inQA') {
-          notification.notifyEAWhenEiCRequestsEQAApproval()
-        } else {
-          notification.notifyEAWhenEiCMakesFinalDecision()
-        }
+      if (recommendation === 'publish' && collection.status === 'inQA') {
+        notification.notifyEAWhenEiCRequestsEQAApproval()
+      }
+
+      if (recommendation === 'publish' && collection.status === 'accepted') {
+        notification.notifyEAWhenEiCMakesFinalDecision()
       }
 
       if (hasPeerReview && (recommendation !== 'publish' || hasEQA)) {
diff --git a/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js b/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js
index 04154a845..c73ab4ad4 100644
--- a/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js
+++ b/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js
@@ -51,7 +51,6 @@ module.exports = ({ Collection, Fragment, User }) => async (req, res) => {
       })
     }
 
-    delete collection.technicalChecks.token
     if (agree) {
       if (step === TECHNICAL_STEPS.EQA) {
         collection.technicalChecks.eqa = true
@@ -61,6 +60,7 @@ module.exports = ({ Collection, Fragment, User }) => async (req, res) => {
       }
     }
 
+    delete collection.technicalChecks.token
     collection.status = setNewStatus(step, agree)
     await collection.save()
 
-- 
GitLab