Polarcraft/web/server/api/team/acceptinvite.js

19 lines
591 B
JavaScript
Raw Normal View History

2023-05-09 13:57:01 +02:00
import { ObjectId } from 'mongodb'
export default defineEventHandler(async (event) => {
const { teamId } = await readBody(event);
const user = await getAuth(event)
const teamsColl = db.collection('teams')
const usersColl = db.collection('users')
const team = await teamsColl.findOneAndUpdate({ _id: new ObjectId(teamId) }, { $inc: { count: 1 } })
2023-05-09 16:01:19 +02:00
if (!team.value) return createError({ statusCode: 500, statusMessage: 'Team niet gevonden'})
2023-05-09 13:57:01 +02:00
await usersColl.updateOne({ _id: new ObjectId(user._id) }, { $set: { 'team.id': teamId, 'team.admin': false }})
return team
});