Polarcraft/web/server/api/team/members.js
2023-05-09 13:57:01 +02:00

18 lines
461 B
JavaScript

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: 'No users were found' })
}
const users = [];
for await (const doc of cursor) {
users.push(doc)
}
return users;
});