Skip to content
Snippets Groups Projects
Commit 694814bd authored by Sebastian Mihalache's avatar Sebastian Mihalache :hammer_pick:
Browse files

fix(mts-package): fix CR notes

parent a2333d2e
No related branches found
No related tags found
3 merge requests!160Update staging with master features,!156Develop,!148Hin 1098
...@@ -2,7 +2,7 @@ const { get, remove } = require('lodash') ...@@ -2,7 +2,7 @@ const { get, remove } = require('lodash')
const config = require('config') const config = require('config')
const User = require('./User') const User = require('./User')
const { recommendations: confRecommendations } = config const { recommendations: configRecommendations } = config
class Fragment { class Fragment {
constructor({ fragment }) { constructor({ fragment }) {
...@@ -151,26 +151,36 @@ class Fragment { ...@@ -151,26 +151,36 @@ class Fragment {
} }
async getReviewersAndEditorsData({ collection, UserModel }) { async getReviewersAndEditorsData({ collection, UserModel }) {
const { recommendations } = this.fragment const {
invitations = [],
recommendations = [],
submitted = Date.now(),
} = this.fragment
const revAndEditorData = await Promise.all( const revAndEditorData = await Promise.all(
recommendations.map(async rec => { recommendations.map(async rec => {
const user = await UserModel.find(rec.userId) const user = await UserModel.find(rec.userId)
let assignmentDate, isReviewer let assignmentDate, isReviewer
if (rec.recommendationType === confRecommendations.type.editor) { 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) { if (user.id === collection.handlingEditor.id) {
const editorInvitation = collection.invitations.find( const editorInvitation = collection.invitations.find(
inv => inv.userId === user.id, inv => inv.userId === user.id,
) )
assignmentDate = editorInvitation.respondedOn assignmentDate = editorInvitation.respondedOn
} else { } else {
assignmentDate = this.fragment.submitted assignmentDate = submitted
} }
isReviewer = false isReviewer = false
} else { } else {
const reviewerInvitation = this.fragment.invitations.find( const reviewerInvitation = invitations.find(
inv => inv.userId === user.id, inv => inv.userId === user.id,
) )
assignmentDate = reviewerInvitation.respondedOn assignmentDate = reviewerInvitation.respondedOn
...@@ -186,8 +196,8 @@ class Fragment { ...@@ -186,8 +196,8 @@ class Fragment {
country: user.country, country: user.country,
lastName: user.lastName, lastName: user.lastName,
firstName: user.firstName, firstName: user.firstName,
submissionDate: rec.createdOn,
affiliation: user.affiliation, affiliation: user.affiliation,
submissionDate: rec.createdOn,
} }
}), }),
) )
......
...@@ -2,6 +2,7 @@ const uuid = require('uuid') ...@@ -2,6 +2,7 @@ const uuid = require('uuid')
const { pick, get, set, has, isEmpty } = require('lodash') const { pick, get, set, has, isEmpty } = require('lodash')
const config = require('config') const config = require('config')
const { v4 } = require('uuid') const { v4 } = require('uuid')
const logger = require('@pubsweet/logger')
const { const {
services, services,
...@@ -94,24 +95,33 @@ module.exports = models => async (req, res) => { ...@@ -94,24 +95,33 @@ module.exports = models => async (req, res) => {
// the manuscript has not yet passed through the EQA process so we need to upload it to the FTP server // the manuscript has not yet passed through the EQA process so we need to upload it to the FTP server
if (isEditorInChief && recommendation === 'publish' && !hasEQA) { if (isEditorInChief && recommendation === 'publish' && !hasEQA) {
if (features.mts) { if (features.mts) {
collection.fragments.forEach(async fragmentId => { await Promise.all(
const fragment = await models.Fragment.find(fragmentId) collection.fragments.map(async fragmentId => {
const fragmentHelper = new Fragment({ fragment }) const fragment = await models.Fragment.find(fragmentId)
const fragmentHelper = new Fragment({ fragment })
const fragmentUsers = await fragmentHelper.getReviewersAndEditorsData(
{ let fragmentUsers = []
collection, try {
UserModel: models.User, fragmentUsers = await fragmentHelper.getReviewersAndEditorsData({
}, collection,
) UserModel: models.User,
})
await sendMTSPackage({
collection, await sendMTSPackage({
fragment, collection,
isEQA: true, fragment,
fragmentUsers, isEQA: true,
}) fragmentUsers,
}) })
} catch (e) {
logger.error(e)
}
}),
).catch(e =>
res.status(500).json({
error: 'Something went wrong.',
}),
)
} }
collection.status = 'inQA' collection.status = 'inQA'
......
...@@ -5,8 +5,6 @@ const { set, get, reduce, isEmpty, capitalize } = require('lodash') ...@@ -5,8 +5,6 @@ const { set, get, reduce, isEmpty, capitalize } = require('lodash')
const manuscriptTypes = config.get('journalConfig.manuscriptTypes') const manuscriptTypes = config.get('journalConfig.manuscriptTypes')
// const { defaultConfig, defaultParseXmlOptions } = require('../config/default')
module.exports = { module.exports = {
setMetadata: ({ metadata, jsonTemplate, options, fileName }) => { setMetadata: ({ metadata, jsonTemplate, options, fileName }) => {
const titleGroup = { const titleGroup = {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment