From 328a85c6225ea35f9e696accec43cedac9c2ae59 Mon Sep 17 00:00:00 2001 From: Andrei Cioromila <andrei.cioromila@thinslices.com> Date: Mon, 3 Dec 2018 11:41:56 +0200 Subject: [PATCH] refactor(manuscript-manager): move fragments retrieval to strategy --- .../src/routes/fragmentsRecommendations/post.js | 15 +-------------- .../strategies/hePublish.js | 3 ++- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js index 1f43c011c..0a70507cc 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js @@ -32,7 +32,7 @@ module.exports = models => async (req, res) => { const { collectionId, fragmentId } = req.params - let collection, fragment, fragments + let collection, fragment try { collection = await models.Collection.find(collectionId) @@ -50,18 +50,6 @@ module.exports = models => async (req, res) => { const collectionHelper = new Collection({ collection }) - try { - fragments = await collectionHelper.getAllFragments({ - FragmentModel: models.Fragment, - }) - } catch (e) { - const notFoundError = await services.handleNotFoundError(e, 'Item') - fragments = [] - return res.status(notFoundError.status).json({ - error: notFoundError.message, - }) - } - const authsome = authsomeHelper.getAuthsome(models) const target = { fragment, @@ -143,7 +131,6 @@ module.exports = models => async (req, res) => { await strategies[role][recommendation].execute({ userId, models, - fragments, notification, fragmentHelper, collectionHelper, diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/strategies/hePublish.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/strategies/hePublish.js index 73c88c434..238efbc14 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/strategies/hePublish.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/strategies/hePublish.js @@ -1,12 +1,13 @@ module.exports = { execute: async ({ userId, - fragments, notification, fragmentHelper, collectionHelper, newRecommendation, }) => { + const fragments = await collectionHelper.collection.getFragments() + if (!collectionHelper.canHEMakeRecommendation(fragments, fragmentHelper)) { throw new Error('Cannot publish without at least one reviewer report.') } -- GitLab