Skip to content
Snippets Groups Projects
Commit 0b4d9ec6 authored by Sebastian Mihalache's avatar Sebastian Mihalache
Browse files

feat(component-manuscript-manager): move new version into fragment revision property

parent 7683a599
No related branches found
No related tags found
1 merge request!14Sprint #15
......@@ -46,12 +46,10 @@ class Email {
const reviewerInvitations = fragmentHelper.getReviewerInvitations({
agree,
})
const hasReview = invUserId => rec =>
rec.recommendationType === 'review' &&
rec.submittedOn &&
invUserId === rec.userId
const reviewerPromises = await reviewerInvitations.map(async inv => {
if (!agree) return UserModel.find(inv.userId)
const submittedReview = recommendations.find(hasReview(inv.userId))
......
......@@ -106,6 +106,22 @@ class Fragment {
(rec.recommendation === 'minor' || rec.recommendation === 'major'),
)
}
async getInvitationsForSubmittingReviewers() {
const { fragment: { recommendations = [] } } = this
const agreedInvitations = this.getReviewerInvitations({
agree: true,
})
return agreedInvitations.filter(async inv =>
recommendations.find(hasReview(inv.userId)),
)
}
}
const hasReview = invUserId => rec =>
rec.recommendationType === 'review' &&
rec.submittedOn &&
invUserId === rec.userId
module.exports = Fragment
......@@ -19,13 +19,13 @@ module.exports = models => async (req, res) => {
return res.status(400).json({
error: `Collection and fragment do not match.`,
})
const fragLength = collection.fragments.length
if (fragLength < 2) {
fragment = await models.Fragment.find(fragmentId)
if (!fragment.revision) {
return res.status(400).json({
error: 'No previous version has been found.',
error: 'No revision has been found.',
})
}
fragment = await models.Fragment.find(fragmentId)
const authsome = authsomeHelper.getAuthsome(models)
const target = {
......@@ -47,7 +47,10 @@ module.exports = models => async (req, res) => {
})
const userHelper = new User({ UserModel: models.User })
const reviewerIds = fragment.invitations.map(inv => {
let newFragment = new models.Fragment(fragment.revision)
newFragment = await newFragment.save()
const reviewerIds = newFragment.invitations.map(inv => {
const { userId } = inv
return userId
})
......@@ -65,7 +68,7 @@ module.exports = models => async (req, res) => {
}),
)
const authorIds = fragment.authors.map(auth => {
const authorIds = newFragment.authors.map(auth => {
const { id } = auth
return id
})
......@@ -89,15 +92,10 @@ module.exports = models => async (req, res) => {
authorIds.forEach(id =>
userHelper.updateUserTeams({
userId: id,
teamId: reviewersTeam.id,
teamId: authorsTeam.id,
}),
)
const previousFragment = await models.Fragment.find(
collection.fragments[fragLength - 2],
)
fragmentHelper.fragment = previousFragment
const heRecommendation = fragmentHelper.getHeRequestToRevision()
if (!heRecommendation) {
return res.status(400).json({
......@@ -109,8 +107,8 @@ module.exports = models => async (req, res) => {
recommendation: heRecommendation.recommendation,
})
fragment.submitted = Date.now()
fragment = await fragment.save()
newFragment.submitted = Date.now()
newFragment = await newFragment.save()
const parsedFragment = await fragmentHelper.getFragmentData({
handlingEditor: collection.handlingEditor,
......@@ -137,7 +135,7 @@ module.exports = models => async (req, res) => {
})
}
return res.status(200).json(fragment)
return res.status(200).json(newFragment)
} catch (e) {
const notFoundError = await services.handleNotFoundError(e, 'Item')
return res.status(notFoundError.status).json({
......
const uuid = require('uuid')
const { chain } = require('lodash')
const { chain, cloneDeep } = require('lodash')
const {
Email,
services,
......@@ -120,7 +120,15 @@ module.exports = models => async (req, res) => {
recommendation,
comments: newRecommendation.comments,
})
if (['minor', 'major'].includes(recommendation)) {
if (recommendation === 'major') {
fragment.revision = cloneDeep(fragment)
delete fragment.revision.recommendations
delete fragment.revision.id
fragment.revision.invitations = await fragmentHelper.getInvitationsForSubmittingReviewers()
}
email.parsedFragment.newComments = newRecommendation.comments
email.setupAuthorsEmail({
requestToRevision: true,
......
......@@ -111,6 +111,7 @@ module.exports = {
),
}),
),
revision: Joi.object(),
},
],
user: {
......
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