summary refs log tree commit diff
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
commit41f05a5abc9d7a97465700bc040fc398ab209959 (patch)
treee0b6d2a154b8ceb56f990763e14fcee13e5dd4a9
parent:art: sort openapi tags by alphabet (diff)
downloadserver-41f05a5abc9d7a97465700bc040fc398ab209959.tar.xz
:bug: fix guild template create
-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);