2023-05-09 13:57:01 +02:00
|
|
|
import { ObjectId } from 'mongodb'
|
|
|
|
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
|
|
const { userId } = await readBody(event)
|
|
|
|
|
|
|
|
const user = await getAuth(event)
|
|
|
|
|
2023-05-09 16:01:19 +02:00
|
|
|
if (!user.team.admin) return createError({ statusCode: 403, statusMessage: 'Admin team rol vereist' })
|
2023-05-09 13:57:01 +02:00
|
|
|
|
|
|
|
const usersColl = db.collection('users')
|
|
|
|
await usersColl.findOneAndUpdate({ _id: new ObjectId(userId) }, { $set: { 'team.admin': false } });
|
|
|
|
|
|
|
|
return { status: 'Success' }
|
|
|
|
});
|