feat: Added team invite creation

This commit is contained in:
Xeovalyte 2023-06-06 22:28:26 +02:00
parent f9c13e5ada
commit 70b0b86a23
4 changed files with 22 additions and 2 deletions

View File

@ -3,6 +3,11 @@ export default defineEventHandler(async (event) => {
if (teamId === '@current') {
const user = await getUser('@me', event)
if (!user.team) {
throw createError({ statusCode: 400, statusMessage: 'User must be in a team' })
}
teamId = user.team._id.toString()
}

View File

@ -0,0 +1,15 @@
export default defineEventHandler(async (event) => {
const { teamId } = await readBody(event)
const userId: string = event.context.params ? event.context.params.id : '@me'
const user = await getUser(userId, event)
const { teamInvites } = await UserModel.findByIdAndUpdate(user._id, {
$addToSet: {
teamInvites: teamId
}
}) ?? { teamInvites: [] }
return teamInvites
})

View File

@ -18,7 +18,7 @@ const userSchema = new Schema({
teamAdmin: Boolean
},
teamInvites: [
Types.ObjectId
{ type: Types.ObjectId, ref: 'Team' }
]
})

View File

@ -16,7 +16,7 @@ declare global {
uuid: string,
username: string
},
teamInvites: string[],
teamInvites: Types.ObjectId[],
role: {
admin: boolean,
moderator: boolean,