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

🐛 fix Member not deleted on guild delete

This commit is contained in:
Flam3rboy 2021-08-10 00:15:44 +02:00
parent dd2f978585
commit 96c55f6c6c

View File

@ -4,6 +4,7 @@ import {
GuildDeleteEvent, GuildDeleteEvent,
GuildModel, GuildModel,
InviteModel, InviteModel,
MemberModel,
MessageModel, MessageModel,
RoleModel, RoleModel,
UserModel UserModel
@ -30,13 +31,16 @@ router.post("/", async (req: Request, res: Response) => {
guild_id: guild_id guild_id: guild_id
} as GuildDeleteEvent); } as GuildDeleteEvent);
await GuildModel.deleteOne({ id: guild_id }).exec(); await Promise.all([
await UserModel.updateMany({ guilds: guild_id }, { $pull: { guilds: guild_id } }).exec(); GuildModel.deleteOne({ id: guild_id }).exec(),
await RoleModel.deleteMany({ guild_id }).exec(); UserModel.updateMany({ guilds: guild_id }, { $pull: { guilds: guild_id } }).exec(),
await ChannelModel.deleteMany({ guild_id }).exec(); RoleModel.deleteMany({ guild_id }).exec(),
await EmojiModel.deleteMany({ guild_id }).exec(); ChannelModel.deleteMany({ guild_id }).exec(),
await InviteModel.deleteMany({ guild_id }).exec(); EmojiModel.deleteMany({ guild_id }).exec(),
await MessageModel.deleteMany({ guild_id }).exec(); InviteModel.deleteMany({ guild_id }).exec(),
MessageModel.deleteMany({ guild_id }).exec(),
MemberModel.deleteMany({ guild_id }).exec()
]);
return res.sendStatus(204); return res.sendStatus(204);
}); });