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

15 lines
457 B
JavaScript

import { ObjectId } from 'mongodb'
export default defineEventHandler(async (event) => {
const { userId } = await readBody(event)
const user = await getAuth(event)
if (!user.team.admin) return createError({ statusCode: 403, statusMessage: 'Admin team rol vereist' })
const usersColl = db.collection('users')
await usersColl.findOneAndUpdate({ _id: new ObjectId(userId) }, { $set: { 'team.admin': false } });
return { status: 'Success' }
});