summary refs log tree commit diff
path: root/src/routes/guilds/#guild_id/channels.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/guilds/#guild_id/channels.ts')
-rw-r--r--src/routes/guilds/#guild_id/channels.ts37
1 files changed, 2 insertions, 35 deletions
diff --git a/src/routes/guilds/#guild_id/channels.ts b/src/routes/guilds/#guild_id/channels.ts

index 5c90b5b9..9d8a95b0 100644 --- a/src/routes/guilds/#guild_id/channels.ts +++ b/src/routes/guilds/#guild_id/channels.ts
@@ -13,6 +13,7 @@ import { HTTPError } from "lambert-server"; import { ChannelModifySchema } from "../../../schema/Channel"; import { emitEvent } from "../../../util/Event"; import { check } from "../../../util/instanceOf"; +import { createChannel } from "../../../util/Channel"; const router = Router(); router.get("/", async (req, res) => { @@ -26,41 +27,7 @@ router.post("/", check(ChannelModifySchema), async (req, res) => { const { guild_id } = req.params; const body = req.body as ChannelModifySchema; - if (!body.permission_overwrites) body.permission_overwrites = []; - if (!body.topic) body.topic = ""; - if (!body.rate_limit_per_user) body.rate_limit_per_user = 0; - - switch (body.type) { - case ChannelType.DM: - case ChannelType.GROUP_DM: - throw new HTTPError("You can't create a dm channel in a guild"); - // TODO: - case ChannelType.GUILD_STORE: - throw new HTTPError("Not yet supported"); - case ChannelType.GUILD_NEWS: - // TODO: check if guild is community server - } - - if (body.parent_id) { - const exists = await ChannelModel.findOne({ id: body.parent_id }, { guild_id: true }).exec(); - if (!exists) throw new HTTPError("Parent id channel doesn't exist", 400); - if (exists.guild_id !== guild_id) throw new HTTPError("The category channel needs to be in the guild"); - } - - const guild = await GuildModel.findOne({ id: guild_id }, { id: true }).exec(); - if (!guild) throw new HTTPError("Guild not found", 404); - - const channel = { - ...body, - id: Snowflake.generate(), - created_at: new Date(), - guild_id, - recipients: null - }; - - await new ChannelModel(channel).save(); - - await emitEvent({ event: "CHANNEL_CREATE", data: channel, guild_id } as ChannelCreateEvent); + const channel = await createChannel({ ...body, guild_id }, req.user_id); res.json(channel); });