From 7ff1ecabe7102d77472313f3a02d70e54bf23cab Mon Sep 17 00:00:00 2001
From: Andrei Cioromila <andrei.cioromila@thinslices.com>
Date: Fri, 16 Nov 2018 16:52:53 +0200
Subject: [PATCH] fix(manuscript-manager): await for manuscript status update
 to guarantee data integrity

---
 .../src/services/Collection.js                     | 14 ++++++--------
 .../src/routes/fragmentsRecommendations/post.js    |  2 +-
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/packages/component-helper-service/src/services/Collection.js b/packages/component-helper-service/src/services/Collection.js
index 2fe550223..6e05d9a58 100644
--- a/packages/component-helper-service/src/services/Collection.js
+++ b/packages/component-helper-service/src/services/Collection.js
@@ -92,18 +92,16 @@ class Collection {
   async updateStatusOnRecommendation({ isEditorInChief, recommendation }) {
     if (isEditorInChief) {
       if (recommendation === 'return-to-handling-editor') {
-        this.updateStatus({ newStatus: 'reviewCompleted' })
-      } else {
-        this.updateFinalStatusByRecommendation({
-          recommendation,
-        })
+        return this.updateStatus({ newStatus: 'reviewCompleted' })
       }
-    } else {
-      this.updateStatusByRecommendation({
+      return this.updateFinalStatusByRecommendation({
         recommendation,
-        isHandlingEditor: true,
       })
     }
+    return this.updateStatusByRecommendation({
+      recommendation,
+      isHandlingEditor: true,
+    })
   }
 
   getHELastName() {
diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js
index f546274ae..253124165 100644
--- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js
+++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js
@@ -127,7 +127,7 @@ module.exports = models => async (req, res) => {
   newRecommendation.comments = comments || undefined
 
   if (recommendationType === 'editorRecommendation') {
-    collectionHelper.updateStatusOnRecommendation({
+    await collectionHelper.updateStatusOnRecommendation({
       isEditorInChief,
       recommendation,
     })
-- 
GitLab