diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-12-23 20:02:26 +1100 |
---|---|---|
committer | Puyodead1 <puyodead@proton.me> | 2023-03-18 19:26:15 -0400 |
commit | 2bae8429269d72bca492cc076e99dfaa7cbd5a62 (patch) | |
tree | d7855a3b66942071453edad60c0f70ae0676b8e1 /src/api/routes | |
parent | fix discord connection (diff) | |
download | server-2bae8429269d72bca492cc076e99dfaa7cbd5a62.tar.xz |
Delete connections
Diffstat (limited to 'src/api/routes')
-rw-r--r-- | src/api/routes/users/@me/connections/#connection_name/#connection_id/index.ts | 25 |
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; |