summary refs log tree commit diff
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
commit4003fef534a9b8fb2a075daa05749e3ec16cccec (patch)
tree81705ddb2be746807998daf1e13895b47edee9f8
parent:arrow_up: update package (diff)
downloadserver-4003fef534a9b8fb2a075daa05749e3ec16cccec.tar.xz
:bug: fix vanity url
-rw-r--r--api/package-lock.json1
-rw-r--r--api/src/routes/guilds/#guild_id/vanity-url.ts7
2 files changed, 5 insertions, 3 deletions
diff --git a/api/package-lock.json b/api/package-lock.json
index 79889f8a..fd9c68b4 100644
--- a/api/package-lock.json
+++ b/api/package-lock.json
@@ -68,6 +68,7 @@
 			}
 		},
 		"../util": {
+			"name": "@fosscord/util",
 			"version": "1.0.0",
 			"hasInstallScript": true,
 			"license": "GPLV3",
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,