From 6f9f144278dee2005caacd5f2bb1147f6b81b03c Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sat, 14 Aug 2021 13:55:51 +0200 Subject: :bug: fix guild create with channel template --- api/src/routes/guilds/index.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'api') diff --git a/api/src/routes/guilds/index.ts b/api/src/routes/guilds/index.ts index c97a8205..e0cb3325 100644 --- a/api/src/routes/guilds/index.ts +++ b/api/src/routes/guilds/index.ts @@ -80,7 +80,27 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) = }).save() ]); - await createChannel({ name: "general", type: 0, guild_id, position: 0, permission_overwrites: [] }, req.user_id); + if (!body.channels || !body.channels.length) body.channels = [{ id: "01", type: 0, name: "general" }]; + + const ids = new Map(); + + body.channels.forEach((x) => { + if (x.id) { + ids.set(x.id, Snowflake.generate()); + } + }); + + await Promise.all( + body.channels?.map((x) => { + var id = ids.get(x.id) || Snowflake.generate(); + + // TODO: should we abort if parent_id is a category? (or not to allow sub category channels) + var parent_id = ids.get(x.parent_id); + + return createChannel({ ...x, guild_id, id, parent_id }, req.user_id, { keepId: true, skipExistsCheck: true }); + }) + ); + await addMember(req.user_id, guild_id); res.status(201).json({ id: guild.id }); -- cgit 1.4.1