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