Polarcraft/webv2/server/api/users/[id]/teamInvites.post.ts

22 lines
495 B
TypeScript
Raw Normal View History

2023-06-06 22:28:26 +02:00
export default defineEventHandler(async (event) => {
const { teamId } = await readBody(event)
2023-06-24 13:27:33 +02:00
console.log(teamId)
2023-06-06 22:28:26 +02:00
const userId: string = event.context.params ? event.context.params.id : '@me'
2023-06-07 22:29:18 +02:00
if (userId === '@me') {
throw createError({ statusCode: 400, statusMessage: 'Cannot invite current user to a team' })
}
2023-06-06 22:28:26 +02:00
const user = await getUser(userId, event)
2023-06-24 13:27:33 +02:00
await UserModel.findByIdAndUpdate(user._id, {
2023-06-06 22:28:26 +02:00
$addToSet: {
teamInvites: teamId
}
2023-06-24 13:27:33 +02:00
})
2023-06-06 22:28:26 +02:00
2023-06-24 13:27:33 +02:00
return user
2023-06-06 22:28:26 +02:00
})