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 })