feat(api): add endpoint to promote/demote a user to/from an admin
This commit is contained in:
parent
309e880b69
commit
66cfee819d
15
server/api/user/[id]/admin.post.ts
Normal file
15
server/api/user/[id]/admin.post.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import isAdmin from "~/lib/server/middlewareButNotReally/isAdmin";
|
||||
import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn";
|
||||
import { User } from "~/models/user";
|
||||
|
||||
export default eventHandler(async (ev) => {
|
||||
isLoggedIn(ev);
|
||||
isAdmin(ev);
|
||||
const b = await readBody(ev);
|
||||
let idee = parseInt(getRouterParam(ev, "id")!);
|
||||
await User.findByIdAndUpdate(idee, {
|
||||
$set: {
|
||||
"profile.isAdmin": b.promote,
|
||||
},
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user