feat: Added team leave
All checks were successful
Build and Deploy / Deploy Web (push) Successful in 1m3s
Build and Deploy / Deploy Discord Bot (push) Successful in 43s

This commit is contained in:
2023-06-06 18:22:36 +02:00
parent 034e203c1e
commit f9c13e5ada
7 changed files with 64 additions and 17 deletions

View File

@@ -0,0 +1,30 @@
export default defineEventHandler(async (event) => {
let teamId: string = event.context.params ? event.context.params.id : '@current'
const userId: string = event.context.params ? event.context.params.userId : '@me'
const user = await getUser(userId, event)
if (!user.team) {
throw createError({ statusCode: 400, statusMessage: 'User must be in a team' })
}
if (teamId === '@current') {
teamId = user.team._id.toString()
}
const team = await TeamModel.findOneAndUpdate({ _id: user.team._id }, {
$pull: {
members: user._id
}
}, { returnDocument: 'after' })
if (team && team.members.length < 1) {
team.deleteOne()
}
user.team = undefined
await user.save()
return ''
})