From 07fb93a4e6b14fa5f2ab890255d0eb054414832f Mon Sep 17 00:00:00 2001 From: stefan080106 Date: Sat, 24 Apr 2021 01:25:20 +0200 Subject: [PATCH] :construction: add guild channel delete route --- src/routes/channels/#channel_id/index.ts | 27 +++++++++++++++++++++++- src/routes/guilds/index.ts | 2 ++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/routes/channels/#channel_id/index.ts b/src/routes/channels/#channel_id/index.ts index 93c33ea5..f6970df3 100644 --- a/src/routes/channels/#channel_id/index.ts +++ b/src/routes/channels/#channel_id/index.ts @@ -1,5 +1,30 @@ +import { ChannelModel, getPermission, toObject } from "@fosscord/server-util"; import { Router } from "express"; +import { HTTPError } from "lambert-server"; const router: Router = Router(); -// TODO: +// TODO: delete channel +// TODO: Get channel + +router.delete("/", async(req,res)=>{ + const {channel_id} = req.params + + const channel = await ChannelModel.findOne({ id: channel_id }, { guild_id: true, type: true, permission_overwrites: true }).exec(); + if (!channel) throw new HTTPError("Channel not found", 404); + if (channel.guild_id) { + const permission = await getPermission(req.user_id, channel.guild_id) + permission.hasThrow("MANAGE_CHANNELS") + + // TODO Channel Update Gateway event will fire for each of them + await ChannelModel.updateMany({parent_id: channel_id}, {$set: {channel_id: null}}).exec() + + await ChannelModel.deleteOne({id: channel_id}) + } + + // TODO: Dm channel "close" not delete + + const data = toObject(channel); + //TODO: Reload channel list if request successful + res.send(data) +}) export default router; diff --git a/src/routes/guilds/index.ts b/src/routes/guilds/index.ts index 6d9b7c1b..bd491e86 100644 --- a/src/routes/guilds/index.ts +++ b/src/routes/guilds/index.ts @@ -9,6 +9,8 @@ import { addMember } from "../../util/Member"; const router: Router = Router(); +//TODO: create default channel + router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) => { const body = req.body as GuildCreateSchema;