summary refs log tree commit diff
path: root/api/src/routes/guilds
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-05 17:00:43 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-05 17:00:43 +0200
commit334a357c6dec14ecb05f92a6f524f69b6d4c21e2 (patch)
treedf7dc30356607749aadf2f0e100a20f9a8461f20 /api/src/routes/guilds
parent:sparkles: auto register guest account (diff)
downloadserver-334a357c6dec14ecb05f92a6f524f69b6d4c21e2.tar.xz
:bug: fix guild create with client template
Diffstat (limited to 'api/src/routes/guilds')
-rw-r--r--api/src/routes/guilds/index.ts38
1 files changed, 17 insertions, 21 deletions
diff --git a/api/src/routes/guilds/index.ts b/api/src/routes/guilds/index.ts
index 6a325ae2..48aab092 100644
--- a/api/src/routes/guilds/index.ts
+++ b/api/src/routes/guilds/index.ts
@@ -31,7 +31,7 @@ router.post("/", route({ body: "GuildCreateSchema" }), async (req: Request, res:
 
 	const guild_id = Snowflake.generate();
 
-	await Guild.insert({
+	await new Guild({
 		name: body.name,
 		icon: await handleFile(`/icons/${guild_id}`, body.icon as string),
 		region: Config.get().regions.default,
@@ -61,10 +61,10 @@ router.post("/", route({ body: "GuildCreateSchema" }), async (req: Request, res:
 			welcome_channels: []
 		},
 		widget_enabled: false
-	});
+	}).save();
 
 	// we have to create the role _after_ the guild because else we would get a "SQLITE_CONSTRAINT: FOREIGN KEY constraint failed" error
-	await Role.insert({
+	await new Role({
 		id: guild_id,
 		guild_id: guild_id,
 		color: 0,
@@ -74,7 +74,7 @@ router.post("/", route({ body: "GuildCreateSchema" }), async (req: Request, res:
 		name: "@everyone",
 		permissions: String("2251804225"),
 		position: 0
-	});
+	}).save();
 
 	if (!body.channels || !body.channels.length) body.channels = [{ id: "01", type: 0, name: "general" }];
 
@@ -86,23 +86,19 @@ router.post("/", route({ body: "GuildCreateSchema" }), async (req: Request, res:
 		}
 	});
 
-	await Promise.all(
-		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
-				});
-			})
-	);
+	for (const channel of body.channels?.sort((a, b) => (a.parent_id ? 1 : -1))) {
+		var id = ids.get(channel.id) || Snowflake.generate();
+
+		// TODO: should we abort if parent_id is a category? (to disallow sub category channels)
+		var parent_id = ids.get(channel.parent_id);
+
+		await Channel.createChannel({ ...channel, guild_id, id, parent_id }, req.user_id, {
+			keepId: true,
+			skipExistsCheck: true,
+			skipPermissionCheck: true,
+			skipEventEmit: true
+		});
+	}
 
 	await Member.addToGuild(req.user_id, guild_id);