Allow mods to delete messages

This commit is contained in:
MeowcaTheoRange 2023-09-25 13:37:39 -05:00
parent 482593c0e4
commit 3ff466e346

View file

@ -1,6 +1,10 @@
import { getSingleClan } from "@/lib/trollcall/clan";
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 { NextApiRequest, NextApiResponse } from "next";
@ -16,8 +20,18 @@ export default async function handler(
name: cookies.TROLLCALL_NAME
});
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();
if (!compareLevels(getLevel(thisClan), "MODERATOR"))
return res.status(403).end();
}
console.log(query.clan);
const newMessage = await deleteMessage({
_id: new ObjectId(query.clan)