import { ObjectId } from 'mongodb'

export default defineEventHandler(async (event) => {
  const { id } = await readBody(event);

  const user = await getAuth(event)

  const teamsColl = db.collection('teams')
  const usersColl = db.collection('users')

  const team = await teamsColl.findOne({ _id: new ObjectId(user.team.id) })

  usersColl.updateOne({ _id: new ObjectId(id) }, { $pull: { teamInvites: team._id.toString() } })

  return team
});
