From 2bae8429269d72bca492cc076e99dfaa7cbd5a62 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Fri, 23 Dec 2022 20:02:26 +1100 Subject: [PATCH] Delete connections --- .../#connection_name/#connection_id/index.ts | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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;