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

feat(component-invite): do not add team on second invitation

parent d2451e2c
No related branches found
No related tags found
1 merge request!5Refactor component invite
......@@ -44,22 +44,23 @@ const createNewTeam = async (collectionId, role, userId, TeamModel) => {
const setupManuscriptTeam = async (models, user, collectionId, role) => {
const teams = await models.Team.all()
user.teams = user.teams || []
const filteredTeams = teams.filter(
let foundTeam = teams.find(
team =>
team.group === role &&
team.object.type === 'collection' &&
team.object.id === collectionId,
)
if (filteredTeams.length > 0) {
let team = filteredTeams[0]
team.members.push(user.id)
if (foundTeam !== undefined) {
foundTeam.members.push(user.id)
try {
team = await team.save()
user.teams.push(team.id)
await user.save()
return team
foundTeam = await foundTeam.save()
if (!user.teams.includes(foundTeam.id)) {
user.teams.push(foundTeam.id)
await user.save()
}
return foundTeam
} catch (e) {
logger.error(e)
}
......
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