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

fix(submitRevision): create author team when submitting revision

parent 81cd2b3b
No related branches found
No related tags found
3 merge requests!196S25 - EiC submit revision,!189S25,!177Hin 230 eic request revision
const { union } = require('lodash')
module.exports = { module.exports = {
execute: async ({ models, fragmentHelper, collectionHelper }) => { execute: async ({ models, TeamHelper, fragmentHelper, collectionHelper }) => {
const eicRequestToRevision = fragmentHelper.getLatestEiCRequestToRevision() const eicRequestToRevision = fragmentHelper.getLatestEiCRequestToRevision()
if (!eicRequestToRevision) { if (!eicRequestToRevision) {
throw new Error('No Editor in Chief request to revision has been found.') throw new Error('No Editor in Chief request to revision has been found.')
...@@ -11,6 +13,32 @@ module.exports = { ...@@ -11,6 +13,32 @@ module.exports = {
await fragmentHelper.removeRevision() await fragmentHelper.removeRevision()
const teamHelper = new TeamHelper({
TeamModel: models.Team,
fragmentId: newFragment.id,
})
const authorIds = newFragment.authors.map(auth => {
const { id } = auth
return id
})
let authorsTeam = await teamHelper.getTeam({
role: 'author',
objectType: 'fragment',
})
if (!authorsTeam) {
authorsTeam = await teamHelper.createTeam({
role: 'author',
members: authorIds,
objectType: 'fragment',
})
} else {
authorsTeam.members = union(authorsTeam.members, authorIds)
await authorsTeam.save()
}
await collectionHelper.updateStatus({ newStatus: 'submitted' }) await collectionHelper.updateStatus({ newStatus: 'submitted' })
newFragment.submitted = Date.now() newFragment.submitted = Date.now()
......
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