mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-22 10:22:39 +01:00
Add /users/:id/delete (#926)
This commit is contained in:
parent
daa0268674
commit
27dbeba821
39
src/api/routes/users/#id/delete.ts
Normal file
39
src/api/routes/users/#id/delete.ts
Normal file
@ -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;
|
@ -393,6 +393,13 @@ export interface UserUpdateEvent extends Event {
|
||||
data: User;
|
||||
}
|
||||
|
||||
export interface UserDeleteEvent extends Event {
|
||||
event: "USER_DELETE";
|
||||
data: {
|
||||
user_id: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface VoiceStateUpdateEvent extends Event {
|
||||
event: "VOICE_STATE_UPDATE";
|
||||
data: VoiceState & {
|
||||
@ -533,6 +540,7 @@ export type EventData =
|
||||
| PresenceUpdateEvent
|
||||
| TypingStartEvent
|
||||
| UserUpdateEvent
|
||||
| UserDeleteEvent
|
||||
| VoiceStateUpdateEvent
|
||||
| VoiceServerUpdateEvent
|
||||
| WebhooksUpdateEvent
|
||||
@ -583,6 +591,7 @@ export enum EVENTEnum {
|
||||
PresenceUpdate = "PRESENCE_UPDATE",
|
||||
TypingStart = "TYPING_START",
|
||||
UserUpdate = "USER_UPDATE",
|
||||
UserDelete = "USER_DELETE",
|
||||
WebhooksUpdate = "WEBHOOKS_UPDATE",
|
||||
InteractionCreate = "INTERACTION_CREATE",
|
||||
VoiceStateUpdate = "VOICE_STATE_UPDATE",
|
||||
@ -633,6 +642,7 @@ export type EVENT =
|
||||
| "PRESENCE_UPDATE"
|
||||
| "TYPING_START"
|
||||
| "USER_UPDATE"
|
||||
| "USER_DELETE"
|
||||
| "USER_NOTE_UPDATE"
|
||||
| "WEBHOOKS_UPDATE"
|
||||
| "INTERACTION_CREATE"
|
||||
|
3
src/util/schemas/UserDeleteSchema.ts
Normal file
3
src/util/schemas/UserDeleteSchema.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export interface UserDeleteSchema {
|
||||
user_id: string;
|
||||
}
|
@ -40,6 +40,7 @@ export * from "./TotpDisableSchema";
|
||||
export * from "./TotpEnableSchema";
|
||||
export * from "./VoiceIdentifySchema";
|
||||
export * from "./TotpSchema";
|
||||
export * from "./UserDeleteSchema";
|
||||
export * from "./UserModifySchema";
|
||||
export * from "./UserProfileModifySchema";
|
||||
export * from "./UserSettingsSchema";
|
||||
|
Loading…
Reference in New Issue
Block a user