2023-06-06 22:28:26 +02:00
|
|
|
export default defineEventHandler(async (event) => {
|
|
|
|
const { teamId } = await readBody(event)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
const { teamInvites } = await UserModel.findByIdAndUpdate(user._id, {
|
|
|
|
$addToSet: {
|
|
|
|
teamInvites: teamId
|
|
|
|
}
|
|
|
|
}) ?? { teamInvites: [] }
|
|
|
|
|
|
|
|
return teamInvites
|
|
|
|
})
|