Polarcraft/webv2/server/api/teams/[id]/index.get.ts

16 lines
437 B
TypeScript

export default defineEventHandler(async (event) => {
let teamId: string = event.context.params ? event.context.params.id : '@current'
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()
}
return await TeamModel.findById(teamId).populate('members')
})