19 lines
592 B
JavaScript
19 lines
592 B
JavaScript
|
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 } })
|
||
|
|
||
|
if (!team.value) return createError({ statusCode: 500, statusMessage: 'Could not find team'})
|
||
|
|
||
|
await usersColl.updateOne({ _id: new ObjectId(user._id) }, { $set: { 'team.id': teamId, 'team.admin': false }})
|
||
|
|
||
|
return team
|
||
|
});
|