summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/api/routes/users/@me/connections/#connection_name/#connection_id/index.ts25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/api/routes/users/@me/connections/#connection_name/#connection_id/index.ts b/src/api/routes/users/@me/connections/#connection_name/#connection_id/index.ts
index 3138d872..84863f6a 100644
--- a/src/api/routes/users/@me/connections/#connection_name/#connection_id/index.ts
+++ b/src/api/routes/users/@me/connections/#connection_name/#connection_id/index.ts
@@ -1,5 +1,5 @@
 import { route } from "@fosscord/api";
-import { ConnectedAccount, DiscordApiErrors } from "@fosscord/util";
+import { ConnectedAccount, DiscordApiErrors, emitEvent } from "@fosscord/util";
 import { Request, Response, Router } from "express";
 const router = Router();
 
@@ -44,4 +44,27 @@ router.patch(
 	},
 );
 
+router.delete("/", route({}), async (req: Request, res: Response) => {
+	const { connection_name, connection_id } = req.params;
+
+	const account = await ConnectedAccount.findOneOrFail({
+		where: {
+			user_id: req.user_id,
+			external_id: connection_id,
+			type: connection_name,
+		}
+	});
+
+	await Promise.all([
+		ConnectedAccount.remove(account),
+		emitEvent({
+			event: "USER_CONNECTIONS_UPDATE",
+			data: account,
+			user_id: req.user_id,
+		})
+	]);
+
+	return res.sendStatus(200);
+});
+
 export default router;