From 371dbf25c9d11a776b26e285d4d28a51ab07b4ac Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 25 Apr 2021 19:41:55 +0200 Subject: [PATCH] :sparkles: Message delete route --- .../#channel_id/messages/#message_id/index.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/routes/channels/#channel_id/messages/#message_id/index.ts b/src/routes/channels/#channel_id/messages/#message_id/index.ts index 014daee7..b01a5af2 100644 --- a/src/routes/channels/#channel_id/messages/#message_id/index.ts +++ b/src/routes/channels/#channel_id/messages/#message_id/index.ts @@ -1,6 +1,23 @@ +import { ChannelModel, getPermission, MessageModel } from "@fosscord/server-util"; import { Router } from "express"; +import { HTTPError } from "lambert-server"; +import { check } from "../../../../../util/instanceOf"; const router = Router(); // TODO: +router.delete("/", async (req, res) => { + const { message_id, channel_id } = req.params; + + const channel = await ChannelModel.findOne({ id: channel_id }, { guild_id: true }); + if (!channel) throw new HTTPError("Channel doesn't exist", 404); + + const permission = await getPermission(req.user_id, channel.guild_id, channel_id); + permission.hasThrow("MANAGE_MESSAGES"); + + await MessageModel.deleteOne({ id: message_id }).exec(); + + res.sendStatus(204); +}); + export default router;