1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-05 18:32:33 +01:00

Delete connections

This commit is contained in:
Madeline 2022-12-23 20:02:26 +11:00 committed by Puyodead1
parent 747ff5d322
commit 2bae842926
No known key found for this signature in database
GPG Key ID: A4FA4FEC0DD353FC

View File

@ -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;