diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-14 13:55:51 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-14 13:55:51 +0200 |
commit | 6db76205828e02210a9471d1788510b21ed2cdde (patch) | |
tree | 7bb8f4aab0e7ee7c629766921bafb17f5a6c2bb7 /api/src/routes/guilds | |
parent | :arrow_up: update test client (diff) | |
download | server-6db76205828e02210a9471d1788510b21ed2cdde.tar.xz |
:bug: fix guild create with channel template
Diffstat (limited to 'api/src/routes/guilds')
-rw-r--r-- | api/src/routes/guilds/index.ts | 22 |
1 files changed, 21 insertions, 1 deletions
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 }); |