summary refs log tree commit diff
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-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,