diff --git a/packages/component-helper-service/src/services/Collection.js b/packages/component-helper-service/src/services/Collection.js index 5bfe4ca8e0baf75b49789404eb07e171412474c7..f68f5efc703266a61603804b1f7b7643d4e09d83 100644 --- a/packages/component-helper-service/src/services/Collection.js +++ b/packages/component-helper-service/src/services/Collection.js @@ -116,7 +116,7 @@ class Collection { return allCollectionFragments } - async getReviewerNumber({ reqUser, FragmentModel }) { + async getReviewerNumber({ userId, FragmentModel }) { const allCollectionFragments = await this.getAllCollectionFragments({ FragmentModel, }) @@ -124,7 +124,7 @@ class Collection { allCollectionFragments.map(fragment => fragment.invitations), ) const allNumberedInvitationsForUser = allCollectionInvitations - .filter(invite => invite.userId === reqUser.id) + .filter(invite => invite.userId === userId) .filter(invite => invite.reviewerNumber) if (isEmpty(allNumberedInvitationsForUser)) { diff --git a/packages/component-helper-service/src/tests/collection.test.js b/packages/component-helper-service/src/tests/collection.test.js index fb921025d2f211c198e077e32b141e7ab146eb42..30315ad22e5616910b55751765a8d4b9723ba468 100644 --- a/packages/component-helper-service/src/tests/collection.test.js +++ b/packages/component-helper-service/src/tests/collection.test.js @@ -56,7 +56,7 @@ describe('Collection helper', () => { const FragmentModel = models.Fragment const reviewerNumber = await collectionHelper.getReviewerNumber({ - reqUser: reviewer, + userId: reviewer.id, FragmentModel, }) @@ -71,7 +71,7 @@ describe('Collection helper', () => { const FragmentModel = models.Fragment const reviewerNumber = await collectionHelper.getReviewerNumber({ - reqUser: reviewer, + userId: reviewer.id, FragmentModel, }) @@ -86,7 +86,7 @@ describe('Collection helper', () => { const FragmentModel = models.Fragment const reviewerNumber = await collectionHelper.getReviewerNumber({ - reqUser: answerReviewer, + userId: answerReviewer.id, FragmentModel, }) @@ -101,7 +101,7 @@ describe('Collection helper', () => { const FragmentModel = models.Fragment const reviewerNumber = await collectionHelper.getReviewerNumber({ - reqUser: reviewer, + userId: reviewer.id, FragmentModel, }) diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/patch.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/patch.js index 7846722ed2f83db255a59ff80f95c142ccf2d3ec..7e1e10feb56051d6752ac1e09857546c40120fde 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/patch.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/patch.js @@ -1,3 +1,4 @@ +const { findIndex } = require('lodash') const { services, authsome: authsomeHelper, @@ -64,6 +65,22 @@ module.exports = models => async (req, res) => { } } + if (req.body.submittedOn) { + const collectionHelper = new Collection({ collection }) + const invitationIndex = findIndex(fragment.invitations, [ + 'userId', + req.authInfo.id, + ]) + if (invitationIndex >= 0) { + const FragmentModel = models.Fragment + const reviewerNumber = await collectionHelper.getReviewerNumber({ + userId: req.authInfo.id, + FragmentModel, + }) + fragment.invitations[invitationIndex].reviewerNumber = reviewerNumber + } + } + fragment.save() return res.status(200).json(recommendation) diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js index 922f7c700899d278b83f66bd012a8069e84cfd1f..c5c0da1b480fa703a0609cd662ae85fbf81de693 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js @@ -1,5 +1,5 @@ const uuid = require('uuid') -const { pick, get, set, has, isEmpty, last, findIndex } = require('lodash') +const { pick, get, set, has, isEmpty, last } = require('lodash') const config = require('config') const { v4 } = require('uuid') @@ -197,18 +197,6 @@ module.exports = models => async (req, res) => { } } - const invitationIndex = findIndex(fragment.invitations, [ - 'userId', - reqUser.id, - ]) - if (invitationIndex >= 0) { - const FragmentModel = models.Fragment - const reviewerNumber = await collectionHelper.getReviewerNumber({ - reqUser, - FragmentModel, - }) - fragment.invitations[invitationIndex].reviewerNumber = reviewerNumber - } fragment.recommendations.push(newRecommendation) fragment.save()