diff --git a/webv2/server/api/teams/[id]/index.get.ts b/webv2/server/api/teams/[id]/index.get.ts index a60b1c5..b104456 100644 --- a/webv2/server/api/teams/[id]/index.get.ts +++ b/webv2/server/api/teams/[id]/index.get.ts @@ -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() } diff --git a/webv2/server/api/users/[id]/teamInvites.post.ts b/webv2/server/api/users/[id]/teamInvites.post.ts new file mode 100644 index 0000000..a79392c --- /dev/null +++ b/webv2/server/api/users/[id]/teamInvites.post.ts @@ -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 +}) diff --git a/webv2/server/utils/models.ts b/webv2/server/utils/models.ts index 38ca8a9..091a778 100644 --- a/webv2/server/utils/models.ts +++ b/webv2/server/utils/models.ts @@ -18,7 +18,7 @@ const userSchema = new Schema({ teamAdmin: Boolean }, teamInvites: [ - Types.ObjectId + { type: Types.ObjectId, ref: 'Team' } ] }) diff --git a/webv2/types/global.d.ts b/webv2/types/global.d.ts index 8a57b2e..047ef14 100644 --- a/webv2/types/global.d.ts +++ b/webv2/types/global.d.ts @@ -16,7 +16,7 @@ declare global { uuid: string, username: string }, - teamInvites: string[], + teamInvites: Types.ObjectId[], role: { admin: boolean, moderator: boolean,