15 lines
442 B
JavaScript
15 lines
442 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: 'Forbidden' })
|
||
|
|
||
|
const usersColl = db.collection('users')
|
||
|
await usersColl.findOneAndUpdate({ _id: new ObjectId(userId) },{ $set: { 'team.admin': true } });
|
||
|
|
||
|
return { status: 'Success' }
|
||
|
});
|