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

16 lines
437 B
TypeScript
Raw Normal View History

2023-06-06 18:22:36 +02:00
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)
2023-06-06 22:28:26 +02:00
if (!user.team) {
throw createError({ statusCode: 400, statusMessage: 'User must be in a team' })
}
2023-06-06 18:22:36 +02:00
teamId = user.team._id.toString()
}
return await TeamModel.findById(teamId).populate('members')
2023-06-01 22:06:11 +02:00
})