Skip to content
Snippets Groups Projects
Commit 7d34ecf9 authored by Mihail Hagiu's avatar Mihail Hagiu
Browse files

refactor(ReviewerNumbering): Fixed CR issues

parent d8687f6f
No related branches found
No related tags found
3 merge requests!176Sprint 24,!171Sprint 24,!158Hin 1115
const { flatten, isEmpty, maxBy, get } = require('lodash')
const { isEmpty, maxBy, get, flatMap } = require('lodash')
class Collection {
constructor({ collection = {} }) {
......@@ -120,8 +120,9 @@ class Collection {
const allCollectionFragments = await this.getAllCollectionFragments({
FragmentModel,
})
const allCollectionInvitations = flatten(
allCollectionFragments.map(fragment => fragment.invitations),
const allCollectionInvitations = flatMap(
allCollectionFragments,
fragment => fragment.invitations,
)
const allNumberedInvitationsForUser = allCollectionInvitations
.filter(invite => invite.userId === userId)
......
const { findIndex } = require('lodash')
const { find } = require('lodash')
const {
services,
authsome: authsomeHelper,
......@@ -9,6 +9,7 @@ const Notification = require('../../notifications/notification')
module.exports = models => async (req, res) => {
const { collectionId, fragmentId, recommendationId } = req.params
const userId = req.user
let collection, fragment
try {
collection = await models.Collection.find(collectionId)
......@@ -26,7 +27,7 @@ module.exports = models => async (req, res) => {
if (!recommendation)
return res.status(404).json({ error: 'Recommendation not found.' })
if (recommendation.userId !== req.user)
if (recommendation.userId !== userId)
return res.status(403).json({
error: 'Unauthorized.',
})
......@@ -36,14 +37,14 @@ module.exports = models => async (req, res) => {
fragment,
path: req.route.path,
}
const canPatch = await authsome.can(req.user, 'PATCH', target)
const canPatch = await authsome.can(userId, 'PATCH', target)
if (!canPatch)
return res.status(403).json({
error: 'Unauthorized.',
})
const UserModel = models.User
const reviewer = await UserModel.find(req.user)
const reviewer = await UserModel.find(userId)
Object.assign(recommendation, req.body)
recommendation.updatedOn = Date.now()
......@@ -63,22 +64,17 @@ module.exports = models => async (req, res) => {
const collectionHelper = new Collection({ collection })
collectionHelper.updateStatus({ newStatus: 'reviewCompleted' })
}
}
if (req.body.submittedOn) {
const collectionHelper = new Collection({ collection })
const invitationIndex = findIndex(fragment.invitations, [
const FragmentModel = models.Fragment
const reviewerNumber = await collectionHelper.getReviewerNumber({
userId: req.authInfo.id,
FragmentModel,
})
find(fragment.invitations, [
'userId',
req.authInfo.id,
])
if (invitationIndex >= 0) {
const FragmentModel = models.Fragment
const reviewerNumber = await collectionHelper.getReviewerNumber({
userId: req.authInfo.id,
FragmentModel,
})
fragment.invitations[invitationIndex].reviewerNumber = reviewerNumber
}
userId,
]).reviewerNumber = reviewerNumber
}
fragment.save()
......
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