diff options
author | Erkin Alp Güney <erkinalp9035@gmail.com> | 2023-01-14 11:15:35 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-14 19:15:35 +1100 |
commit | 876c15b1a9ed8ee9343cc0c00743b42c69712a6c (patch) | |
tree | 3ea7c6c211c7b39aa8582980dbccee1dcac9869a /src/api | |
parent | Merge pull request #929 from fosscord/dev/fix-client-script (diff) | |
download | server-876c15b1a9ed8ee9343cc0c00743b42c69712a6c.tar.xz |
Add /users/:id/delete (#926)
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/routes/users/#id/delete.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/api/routes/users/#id/delete.ts b/src/api/routes/users/#id/delete.ts new file mode 100644 index 00000000..2c08635b --- /dev/null +++ b/src/api/routes/users/#id/delete.ts @@ -0,0 +1,39 @@ +import { route } from "@fosscord/api"; +import { + emitEvent, + Member, + PrivateUserProjection, + User, + UserDeleteEvent, + UserDeleteSchema, +} from "@fosscord/util"; +import { Request, Response, Router } from "express"; + +const router = Router(); + +router.post( + "/", + route({ right: "MANAGE_USERS" }), + async (req: Request, res: Response) => { + + let user = await User.findOneOrFail({ + where: { id: req.params.id }, + select: [...PrivateUserProjection, "data"], + }); + await Promise.all([ + Member.delete({ id: req.params.id }), + User.delete({ id: req.params.id }), + ]); + + // TODO: respect intents as USER_DELETE has potential to cause privacy issues + await emitEvent({ + event: "USER_DELETE", + user_id: req.user_id, + data: { user_id: req.params.id }, + } as UserDeleteEvent); + + res.sendStatus(204); + }, +); + +export default router; |