summary refs log tree commit diff
path: root/api/src
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-16 22:03:30 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-16 22:03:30 +0200
commitdbcd6ec6f98c6ca0735dfaedf323fb3aa53697c4 (patch)
tree452a5dc66511f3622678804819a18f4042e1ff2b /api/src
parent:arrow_up: update package (diff)
downloadserver-dbcd6ec6f98c6ca0735dfaedf323fb3aa53697c4.tar.xz
:bug: fix vanity url
Diffstat (limited to 'api/src')
-rw-r--r--api/src/routes/guilds/#guild_id/vanity-url.ts7
1 files changed, 4 insertions, 3 deletions
diff --git a/api/src/routes/guilds/#guild_id/vanity-url.ts b/api/src/routes/guilds/#guild_id/vanity-url.ts
index 801768fb..7f2cea9e 100644
--- a/api/src/routes/guilds/#guild_id/vanity-url.ts
+++ b/api/src/routes/guilds/#guild_id/vanity-url.ts
@@ -1,6 +1,7 @@
 import { Channel, ChannelType, getPermission, Guild, Invite, trimSpecial } from "@fosscord/util";
 import { Router, Request, Response } from "express";
 import { route } from "@fosscord/api";
+import { HTTPError } from "lambert-server";
 
 const router = Router();
 
@@ -29,14 +30,14 @@ router.patch("/", route({ body: "VanityUrlSchema", permission: "MANAGE_GUILD" })
 	const body = req.body as VanityUrlSchema;
 	const code = body.code?.replace(InviteRegex, "");
 
-	await Invite.findOneOrFail({ code });
+	const invite = await Invite.findOne({ code });
+	if (invite) throw new HTTPError("Invite already exists");
 
 	const guild = await Guild.findOneOrFail({ id: guild_id });
 	const { id } = await Channel.findOneOrFail({ guild_id, type: ChannelType.GUILD_TEXT });
-	guild.vanity_url_code = code;
 
 	Promise.all([
-		guild.save(),
+		Guild.update({ id: guild_id }, { vanity_url_code: code }),
 		Invite.delete({ code: guild.vanity_url_code }),
 		new Invite({
 			code: code,