diff --git a/packages/component-manuscript-manager/src/routes/collections/get.js b/packages/component-manuscript-manager/src/routes/collections/get.js index 1314ffda0107a1e4c80a0edab70561f97db82093..ddeeb504d1efee96f4362a6e72455cb7529298f2 100644 --- a/packages/component-manuscript-manager/src/routes/collections/get.js +++ b/packages/component-manuscript-manager/src/routes/collections/get.js @@ -1,8 +1,3 @@ -const { last, get } = require('lodash') - -const filterDuplicates = collection => - get(collection, 'currentVersion.id') === last(collection.fragments) - const { authsome: authsomeHelper, } = require('pubsweet-component-helper-service') @@ -21,5 +16,5 @@ module.exports = models => async (req, res) => { }) } - res.status(200).json(collections.filter(filterDuplicates)) + res.status(200).json(collections) } diff --git a/packages/xpub-faraday/config/authsome-helpers.js b/packages/xpub-faraday/config/authsome-helpers.js index c92571ecc8808a78710f8631b5fff43629b0d60b..de88ed38e85a7a4c68bd4c70e2c0fb0be4698d83 100644 --- a/packages/xpub-faraday/config/authsome-helpers.js +++ b/packages/xpub-faraday/config/authsome-helpers.js @@ -1,4 +1,4 @@ -const { omit, get, last } = require('lodash') +const { omit, get, last, chain } = require('lodash') const config = require('config') const logger = require('@pubsweet/logger') @@ -207,7 +207,7 @@ const parseUser = ({ user }) => omit(user, sensitiveUserProperties) const getCollections = async ({ user, models }) => { const userPermisssions = await getUserPermissions({ user, Team: models.Team }) - return (await Promise.all( + const collections = (await Promise.all( userPermisssions.map(async up => { let fragment = {} let collection = {} @@ -253,6 +253,11 @@ const getCollections = async ({ user, models }) => { } }), )).filter(Boolean) + return chain(collections) + .sortBy(c => c.currentVersion.version) + .reverse() + .uniqBy('id') + .value() } async function updateReviewerVisibleStatusByInvitation({ @@ -278,6 +283,10 @@ async function updateReviewerVisibleStatusByInvitation({ return get(statuses, `${collection.status}.reviewer.label`) } + if (!invitation) { + return get(statuses, `reviewCompleted.reviewer.label`) + } + return get(invitation, 'hasAnswer', false) && get(invitation, 'isAccepted', false) ? get(statuses, `underReview.reviewer.label`)