Allow mods to delete messages
This commit is contained in:
parent
482593c0e4
commit
3ff466e346
1 changed files with 17 additions and 3 deletions
|
@ -1,6 +1,10 @@
|
||||||
import { getSingleClan } from "@/lib/trollcall/clan";
|
import { getSingleClan } from "@/lib/trollcall/clan";
|
||||||
import { deleteMessage } from "@/lib/trollcall/message";
|
import { deleteMessage } from "@/lib/trollcall/message";
|
||||||
import { compareCredentials } from "@/lib/trollcall/perms";
|
import {
|
||||||
|
compareCredentials,
|
||||||
|
compareLevels,
|
||||||
|
getLevel
|
||||||
|
} from "@/lib/trollcall/perms";
|
||||||
import { ObjectId } from "mongodb";
|
import { ObjectId } from "mongodb";
|
||||||
import { NextApiRequest, NextApiResponse } from "next";
|
import { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
|
||||||
|
@ -16,8 +20,18 @@ export default async function handler(
|
||||||
name: cookies.TROLLCALL_NAME
|
name: cookies.TROLLCALL_NAME
|
||||||
});
|
});
|
||||||
if (checkClan == null) return res.status(404).end();
|
if (checkClan == null) return res.status(404).end();
|
||||||
if (!(await compareCredentials(checkClan, cookies)))
|
if (!(await compareCredentials(checkClan, cookies))) {
|
||||||
|
const thisClan = await getSingleClan({
|
||||||
|
name: cookies.TROLLCALL_NAME
|
||||||
|
});
|
||||||
|
if (
|
||||||
|
thisClan == null ||
|
||||||
|
!(await compareCredentials(thisClan, cookies))
|
||||||
|
)
|
||||||
return res.status(403).end();
|
return res.status(403).end();
|
||||||
|
if (!compareLevels(getLevel(thisClan), "MODERATOR"))
|
||||||
|
return res.status(403).end();
|
||||||
|
}
|
||||||
console.log(query.clan);
|
console.log(query.clan);
|
||||||
const newMessage = await deleteMessage({
|
const newMessage = await deleteMessage({
|
||||||
_id: new ObjectId(query.clan)
|
_id: new ObjectId(query.clan)
|
||||||
|
|
Loading…
Reference in a new issue