Polarcraft/webv2/server/api/teams/index.post.ts
Xeovalyte f9c13e5ada
All checks were successful
Build and Deploy / Deploy Web (push) Successful in 1m3s
Build and Deploy / Deploy Discord Bot (push) Successful in 43s
feat: Added team leave
2023-06-06 18:22:36 +02:00

26 lines
449 B
TypeScript

export default defineEventHandler(async (event) => {
const { name, color, userId } = await readBody(event)
const user = await getUser(userId ?? '@me', event)
if (user.team) {
throw createError({ statusCode: 400, statusMessage: 'User already in a team' })
}
const team = new TeamModel({
name,
color,
members: [
user._id
]
})
await team.save()
user.team = team._id
await user.save()
return team
})