20 lines
526 B
TypeScript
20 lines
526 B
TypeScript
export default defineEventHandler(async (event) => {
|
|
const { teamId } = await readBody(event)
|
|
|
|
const userId: string = event.context.params ? event.context.params.id : '@me'
|
|
|
|
if (userId === '@me') {
|
|
throw createError({ statusCode: 400, statusMessage: 'Cannot invite current user to a team' })
|
|
}
|
|
|
|
const user = await getUser(userId, event)
|
|
|
|
const { teamInvites } = await UserModel.findByIdAndUpdate(user._id, {
|
|
$addToSet: {
|
|
teamInvites: teamId
|
|
}
|
|
}) ?? { teamInvites: [] }
|
|
|
|
return teamInvites
|
|
})
|