1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-11 13:14:06 +01:00

🚧 add guild channel delete route

This commit is contained in:
stefan080106 2021-04-24 01:25:20 +02:00
parent b213e2931a
commit 07fb93a4e6
2 changed files with 28 additions and 1 deletions

View File

@ -1,5 +1,30 @@
import { ChannelModel, getPermission, toObject } from "@fosscord/server-util";
import { Router } from "express"; import { Router } from "express";
import { HTTPError } from "lambert-server";
const router: Router = Router(); 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; export default router;

View File

@ -9,6 +9,8 @@ import { addMember } from "../../util/Member";
const router: Router = Router(); const router: Router = Router();
//TODO: create default channel
router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) => { router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) => {
const body = req.body as GuildCreateSchema; const body = req.body as GuildCreateSchema;