summary refs log tree commit diff
path: root/api/src
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-25 04:20:11 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-25 04:20:11 +0200
commit6229398316b1cfbf110a501a67cbb537aa126549 (patch)
tree66a68229f504d98805a74194c76e9490564998fb /api/src
parent:art: sort openapi tags by alphabet (diff)
downloadserver-6229398316b1cfbf110a501a67cbb537aa126549.tar.xz
:bug: fix guild template create
Diffstat (limited to 'api/src')
-rw-r--r--api/src/routes/guilds/index.ts28
1 files changed, 15 insertions, 13 deletions
diff --git a/api/src/routes/guilds/index.ts b/api/src/routes/guilds/index.ts
index abde147d..6a325ae2 100644
--- a/api/src/routes/guilds/index.ts
+++ b/api/src/routes/guilds/index.ts
@@ -87,19 +87,21 @@ router.post("/", route({ body: "GuildCreateSchema" }), async (req: Request, res:
 	});
 
 	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? (to disallow sub category channels)
-			var parent_id = ids.get(x.parent_id);
-
-			return Channel.createChannel({ ...x, guild_id, id, parent_id }, req.user_id, {
-				keepId: true,
-				skipExistsCheck: true,
-				skipPermissionCheck: true,
-				skipEventEmit: true
-			});
-		})
+		body.channels
+			?.sort((a, b) => (a.parent_id ? -1 : 1))
+			.map((x) => {
+				var id = ids.get(x.id) || Snowflake.generate();
+
+				// TODO: should we abort if parent_id is a category? (to disallow sub category channels)
+				var parent_id = ids.get(x.parent_id);
+
+				return Channel.createChannel({ ...x, guild_id, id, parent_id }, req.user_id, {
+					keepId: true,
+					skipExistsCheck: true,
+					skipPermissionCheck: true,
+					skipEventEmit: true
+				});
+			})
 	);
 
 	await Member.addToGuild(req.user_id, guild_id);