diff --git a/packages/component-helper-service/src/services/Fragment.js b/packages/component-helper-service/src/services/Fragment.js index 31c32f90caee3d4b2aa3fcc467ee0770c875210b..ba56f7a41f116f412842fa721f2336cf6430f169 100644 --- a/packages/component-helper-service/src/services/Fragment.js +++ b/packages/component-helper-service/src/services/Fragment.js @@ -158,57 +158,57 @@ class Fragment { } = this.fragment const revAndEditorData = await Promise.all( - recommendations.map(async rec => { - if ( - rec.recommendationType === configRecommendations.type.review && - !rec.submittedOn - ) { - return null - } - - const user = await UserModel.find(rec.userId) - let assignmentDate, isReviewer - - if (rec.recommendationType === configRecommendations.type.editor) { - if (!collection.handlingEditor) { - throw new Error( - `Collection ${collection.id} does not have a Handling Editor`, - ) - } - if (user.id === collection.handlingEditor.id) { - const editorInvitation = collection.invitations.find( + recommendations + .filter( + rec => + rec.recommendationType === configRecommendations.type.editor || + (rec.recommendationType === configRecommendations.type.review && + rec.submittedOn), + ) + .map(async rec => { + const user = await UserModel.find(rec.userId) + let assignmentDate, isReviewer + + if (rec.recommendationType === configRecommendations.type.editor) { + if (!collection.handlingEditor) { + throw new Error( + `Collection ${collection.id} does not have a Handling Editor`, + ) + } + if (user.id === collection.handlingEditor.id) { + const editorInvitation = collection.invitations.find( + inv => inv.userId === user.id, + ) + assignmentDate = editorInvitation.respondedOn + } else { + assignmentDate = submitted + } + + isReviewer = false + } else { + const reviewerInvitation = invitations.find( inv => inv.userId === user.id, ) - assignmentDate = editorInvitation.respondedOn - } else { - assignmentDate = submitted + assignmentDate = reviewerInvitation.respondedOn + isReviewer = true } - isReviewer = false - } else { - const reviewerInvitation = invitations.find( - inv => inv.userId === user.id, - ) - assignmentDate = reviewerInvitation.respondedOn - isReviewer = true - } - - return { - isReviewer, - assignmentDate, - email: user.email, - title: user.title, - recommendation: rec, - country: user.country, - lastName: user.lastName, - firstName: user.firstName, - affiliation: user.affiliation, - submissionDate: rec.createdOn, - } - }), + return { + isReviewer, + assignmentDate, + email: user.email, + title: user.title, + recommendation: rec, + country: user.country, + lastName: user.lastName, + firstName: user.firstName, + affiliation: user.affiliation, + submissionDate: rec.createdOn, + } + }), ) - return revAndEditorData.filter(Boolean) + return revAndEditorData } }