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

fix(Email): Merge with origin

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