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

index cd03fdbb..b949def0 100644 --- a/src/routes/guilds/#id/channels.ts +++ b/src/routes/guilds/#id/channels.ts
@@ -1,19 +1,20 @@ import { Router } from "express"; -import { ChannelModel, ChannelType, GuildModel, Snowflake } from "fosscord-server-util"; +import { ChannelCreateEvent, ChannelModel, ChannelType, GuildModel, Snowflake, toObject } from "fosscord-server-util"; import { HTTPError } from "lambert-server"; import { ChannelModifySchema } from "../../../schema/Channel"; +import { emitEvent } from "../../../util/Event"; import { check } from "../../../util/instanceOf"; const router = Router(); router.get("/", async (req, res) => { - const guild_id = (req.params.id); - const channels = await ChannelModel.find({ guild_id }).lean().exec(); + const guild_id = req.params.id; + const channels = await ChannelModel.find({ guild_id }).exec(); - res.json(channels); + res.json(toObject(channels)); }); router.post("/", check(ChannelModifySchema), async (req, res) => { - const guild_id = (req.params.id); + const guild_id = req.params.id; const body = req.body as ChannelModifySchema; if (!body.permission_overwrites) body.permission_overwrites = []; if (!body.topic) body.topic = ""; @@ -45,6 +46,8 @@ router.post("/", check(ChannelModifySchema), async (req, res) => { }; await new ChannelModel(channel).save(); + await emitEvent({ event: "CHANNEL_CREATE", data: channel, guild_id } as ChannelCreateEvent); + res.json(channel); });