summary refs log tree commit diff
path: root/src/routes/guilds/#guild_id/channels.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-05-05 15:05:41 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-05-05 15:05:41 +0200
commit87634d552244ce36fe0f39a9e2246f785d3afd58 (patch)
treec6c93aea93d39dbc8d477e0a1124f455ac3333dd /src/routes/guilds/#guild_id/channels.ts
parent:bug: fix test client (diff)
parent[Route] PATCH /guilds/:id/channels (diff)
downloadserver-87634d552244ce36fe0f39a9e2246f785d3afd58.tar.xz
Merge branch 'master' of https://github.com/discord-open-source/discord-api
Diffstat (limited to 'src/routes/guilds/#guild_id/channels.ts')
-rw-r--r--src/routes/guilds/#guild_id/channels.ts24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/routes/guilds/#guild_id/channels.ts b/src/routes/guilds/#guild_id/channels.ts

index 19d466f3..73982ed5 100644 --- a/src/routes/guilds/#guild_id/channels.ts +++ b/src/routes/guilds/#guild_id/channels.ts
@@ -1,5 +1,5 @@ import { Router } from "express"; -import { ChannelCreateEvent, ChannelModel, ChannelType, GuildModel, Snowflake, toObject } from "@fosscord/server-util"; +import { ChannelCreateEvent, ChannelModel, ChannelType, GuildModel, Snowflake, toObject, ChannelUpdateEvent } from "@fosscord/server-util"; import { HTTPError } from "lambert-server"; import { ChannelModifySchema } from "../../../schema/Channel"; import { emitEvent } from "../../../util/Event"; @@ -37,7 +37,7 @@ router.post("/", check(ChannelModifySchema), async (req, res) => { } const guild = await GuildModel.findOne({ id: guild_id }, { id: true }).exec(); - if (!guild) throw new HTTPError("Guild not found", 4040); + if (!guild) throw new HTTPError("Guild not found", 404); const channel = { ...body, @@ -52,4 +52,24 @@ router.post("/", check(ChannelModifySchema), async (req, res) => { res.json(channel); }); +router.patch("/", check(ChannelModifySchema), async (req, res) => { + const { guild_id } = req.params; + const body = req.body as ChannelModifySchema; + + const guild = await GuildModel.findOne({ id: guild_id }, { id: true }).exec(); + if (!guild) throw new HTTPError("Guild not found", 404); + + const channel = { + ...body + }; + const channelm = await ChannelModel.find({ guild_id }).exec(); + if(!channelm) throw new HTTPError("Channel not found", 404); + + await new ChannelModel(channel).save(); + + await emitEvent({ event: "CHANNEL_UPDATE", data: channel } as ChannelUpdateEvent); + + res.json(channel); +}); + export default router;