export default defineEventHandler(async (event) => {
  const user = await getAuth(event)

  const usersColl = db.collection('users')
  const cursor = usersColl.find({ 'team.id': user.team.id })

  if((await usersColl.countDocuments({ 'team.id': user.team.id })) === 0) {
    return createError({ statusCode: 500, statusMessage: 'Geen gebruikers zijn gevonden' })
  }
  
  const users = [];
  for await (const doc of cursor) {
    users.push(doc)
  }

  return users;
});
