summary refs log tree commit diff
path: root/src/routes
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-05-22 17:40:10 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-05-22 17:40:10 +0200
commit4715ef1eab99f8158b4ddaa0b9b7bc9a61d0e337 (patch)
treefec7359718bc811992dbfed76377b075c3171017 /src/routes
parent:art: Move member routes in separate files (diff)
downloadserver-4715ef1eab99f8158b4ddaa0b9b7bc9a61d0e337.tar.xz
:sparkles: createChannel()
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/guilds/#guild_id/channels.ts37
-rw-r--r--src/routes/guilds/#guild_id/index.ts11
-rw-r--r--src/routes/guilds/index.ts4
3 files changed, 5 insertions, 47 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); }); diff --git a/src/routes/guilds/#guild_id/index.ts b/src/routes/guilds/#guild_id/index.ts
index 47675609..9ef0127a 100644 --- a/src/routes/guilds/#guild_id/index.ts +++ b/src/routes/guilds/#guild_id/index.ts
@@ -54,15 +54,4 @@ router.patch("/", check(GuildUpdateSchema), async (req: Request, res: Response) return res.send(data); }); -router.get("/vanity-url", async (req: Request, res: Response) => { - const { guild_id } = req.params; - - const guild = await GuildModel.findOne({ id: guild_id }).exec(); - if (!guild) throw new HTTPError("Guild does not exist", 404); - - if (!guild.vanity_url) throw new HTTPError("This guild has no vanity url", 204); - - return res.json(guild.vanity_url); -}); - export default router; diff --git a/src/routes/guilds/index.ts b/src/routes/guilds/index.ts
index 1ed9d0ff..c286ad51 100644 --- a/src/routes/guilds/index.ts +++ b/src/routes/guilds/index.ts
@@ -6,6 +6,7 @@ import { GuildCreateSchema } from "../../schema/Guild"; import Config from "../../util/Config"; import { getPublicUser } from "../../util/User"; import { addMember } from "../../util/Member"; +import { createChannel } from "../../util/Channel"; const router: Router = Router(); @@ -80,7 +81,8 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) = }).save() ]); - await addMember(req.user_id, guild_id, { guild: guild_doc }); + await createChannel({ name: "general", type: 0, guild_id, position: 0, permission_overwrites: [] }, req.user_id); + await addMember(req.user_id, guild_id); res.status(201).json({ id: guild.id }); });