summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-14 13:55:51 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-14 13:55:51 +0200
commit6f9f144278dee2005caacd5f2bb1147f6b81b03c (patch)
tree6112edd81ff922bc280be4cfb9cd54e05a8fdb3a
parent:arrow_up: update test client (diff)
downloadserver-6f9f144278dee2005caacd5f2bb1147f6b81b03c.tar.xz
:bug: fix guild create with channel template
-rw-r--r--api/src/routes/guilds/index.ts22
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 });