summary refs log tree commit diff
path: root/api/src
diff options
context:
space:
mode:
authorThe Arcane Brony <myrainbowdash949@gmail.com>2021-10-10 17:55:48 +0200
committerThe Arcane Brony <myrainbowdash949@gmail.com>2021-10-10 17:55:48 +0200
commit79aee5145b6b289a001caae516477c8ab641bb8f (patch)
tree9fa55053ec5da0483e1a9de0d97089aef4559068 /api/src
parent:bug: fix null user in identify (diff)
downloadserver-79aee5145b6b289a001caae516477c8ab641bb8f.tar.xz
Fix duplicate key
Diffstat (limited to 'api/src')
-rw-r--r--api/src/routes/guilds/#guild_id/vanity-url.ts9
-rw-r--r--api/src/routes/invites/index.ts1
2 files changed, 3 insertions, 7 deletions
diff --git a/api/src/routes/guilds/#guild_id/vanity-url.ts b/api/src/routes/guilds/#guild_id/vanity-url.ts
index 7f2cea9e..061b317c 100644
--- a/api/src/routes/guilds/#guild_id/vanity-url.ts
+++ b/api/src/routes/guilds/#guild_id/vanity-url.ts
@@ -10,10 +10,10 @@ const InviteRegex = /\W/g;
 router.get("/", route({ permission: "MANAGE_GUILD" }), async (req: Request, res: Response) => {
 	const { guild_id } = req.params;
 
-	const guild = await Guild.findOneOrFail({ where: { id: guild_id }, relations: ["vanity_url"] });
-	if (!guild.vanity_url) return res.json({ code: null });
+	const invite = await Invite.findOne({ where: {guild_id: guild_id, vanity_url: true} });
+	if (!invite) return res.json({ code: null });
 
-	return res.json({ code: guild.vanity_url_code, uses: guild.vanity_url.uses });
+	return res.json({ code: invite.code, uses: invite.uses });
 });
 
 export interface VanityUrlSchema {
@@ -33,12 +33,9 @@ router.patch("/", route({ body: "VanityUrlSchema", permission: "MANAGE_GUILD" })
 	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 });
 
 	Promise.all([
-		Guild.update({ id: guild_id }, { vanity_url_code: code }),
-		Invite.delete({ code: guild.vanity_url_code }),
 		new Invite({
 			code: code,
 			uses: 0,
diff --git a/api/src/routes/invites/index.ts b/api/src/routes/invites/index.ts
index 0fcf7c86..185311bc 100644
--- a/api/src/routes/invites/index.ts
+++ b/api/src/routes/invites/index.ts
@@ -33,7 +33,6 @@ router.delete("/:code", route({}), async (req: Request, res: Response) => {
 
 	await Promise.all([
 		Invite.delete({ code }),
-		Guild.update({ vanity_url_code: code }, { vanity_url_code: undefined }),
 		emitEvent({
 			event: "INVITE_DELETE",
 			guild_id: guild_id,