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

refactor(submitRevision): update author team creation

parent cee0a2f5
No related branches found
No related tags found
3 merge requests!196S25 - EiC submit revision,!189S25,!177Hin 230 eic request revision
......@@ -67,7 +67,7 @@ class User {
async updateUserTeams({ userId, teamId }) {
const user = await this.UserModel.find(userId)
user.teams.push(teamId)
user.save()
await user.save()
}
async getActiveAuthors({ fragmentAuthors }) {
......
const {
Team,
User,
services,
Fragment,
Collection,
......@@ -43,6 +44,7 @@ module.exports = models => async (req, res) => {
const collectionHelper = new Collection({ collection })
const fragmentHelper = new Fragment({ fragment })
const userHelper = new User({ UserModel: models.User })
const strategies = {
he: heRequestRevision,
......@@ -61,6 +63,7 @@ module.exports = models => async (req, res) => {
try {
const newFragment = await strategies[role].execute({
models,
userHelper,
notification,
fragmentHelper,
collectionHelper,
......
const { union } = require('lodash')
module.exports = {
execute: async ({ models, TeamHelper, fragmentHelper, collectionHelper }) => {
execute: async ({
models,
userHelper,
TeamHelper,
fragmentHelper,
collectionHelper,
}) => {
const eicRequestToRevision = fragmentHelper.getLatestEiCRequestToRevision()
if (!eicRequestToRevision) {
throw new Error('No Editor in Chief request to revision has been found.')
......@@ -18,26 +22,16 @@ module.exports = {
fragmentId: newFragment.id,
})
const authorIds = newFragment.authors.map(auth => {
const { id } = auth
return id
})
const authorIds = newFragment.authors.map(auth => auth.id)
let authorsTeam = await teamHelper.getTeam({
const { id: teamId } = await teamHelper.createTeam({
role: 'author',
members: authorIds,
objectType: 'fragment',
})
if (!authorsTeam) {
authorsTeam = await teamHelper.createTeam({
role: 'author',
members: authorIds,
objectType: 'fragment',
})
} else {
authorsTeam.members = union(authorsTeam.members, authorIds)
await authorsTeam.save()
}
authorIds.forEach(id => {
userHelper.updateUserTeams({ userId: id, teamId })
})
await collectionHelper.updateStatus({ newStatus: 'submitted' })
......
const { union } = require('lodash')
module.exports = {
execute: async ({
models,
userHelper,
TeamHelper,
notification,
fragmentHelper,
......@@ -36,26 +35,16 @@ module.exports = {
await newFragment.save()
}
const authorIds = newFragment.authors.map(auth => {
const { id } = auth
return id
})
const authorIds = newFragment.authors.map(auth => auth.id)
let authorsTeam = await teamHelper.getTeam({
const { id: teamId } = await teamHelper.createTeam({
role: 'author',
members: authorIds,
objectType: 'fragment',
})
if (!authorsTeam) {
authorsTeam = await teamHelper.createTeam({
role: 'author',
members: authorIds,
objectType: 'fragment',
})
} else {
authorsTeam.members = union(authorsTeam.members, authorIds)
await authorsTeam.save()
}
authorIds.forEach(id => {
userHelper.updateUserTeams({ userId: id, teamId })
})
const fragments = await collectionHelper.getAllFragments({
FragmentModel: models.Fragment,
......
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