diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-20 20:22:56 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-20 20:22:56 +0200 |
commit | 576cbf5794b2e146892d7080b699882c2ba6ec6a (patch) | |
tree | ba0ee566a013053d90272126f2f5461ad6b1e30b /api/src/routes/guilds/#guild_id/delete.ts | |
parent | :sparkles: finish and fix .delete() for one-to-many relations (diff) | |
download | server-576cbf5794b2e146892d7080b699882c2ba6ec6a.tar.xz |
:bug: fix .delete -> add onDelete: "CASCADE"
Diffstat (limited to 'api/src/routes/guilds/#guild_id/delete.ts')
-rw-r--r-- | api/src/routes/guilds/#guild_id/delete.ts | 12 |
1 files changed, 1 insertions, 11 deletions
diff --git a/api/src/routes/guilds/#guild_id/delete.ts b/api/src/routes/guilds/#guild_id/delete.ts index 7c3c5530..bd158c56 100644 --- a/api/src/routes/guilds/#guild_id/delete.ts +++ b/api/src/routes/guilds/#guild_id/delete.ts @@ -13,15 +13,8 @@ router.post("/", route({}), async (req: Request, res: Response) => { const guild = await Guild.findOneOrFail({ where: { id: guild_id }, select: ["owner_id"] }); if (guild.owner_id !== req.user_id) throw new HTTPError("You are not the owner of this guild", 401); - // do not put everything into promise all, because of "QueryFailedError: SQLITE_CONSTRAINT: FOREIGN KEY constraint failed" - - await Message.delete({ guild_id }); // messages must be deleted before channel - await Promise.all([ - Role.delete({ guild_id }), - Channel.delete({ guild_id }), - Emoji.delete({ guild_id }), - Member.delete({ guild_id }), + Guild.delete({ id: guild_id }), // this will also delete all guild related data emitEvent({ event: "GUILD_DELETE", data: { @@ -31,9 +24,6 @@ router.post("/", route({}), async (req: Request, res: Response) => { } as GuildDeleteEvent) ]); - await Invite.delete({ guild_id }); // invite must be deleted after channel - await Guild.delete({ id: guild_id }); // guild must be deleted after everything else - return res.sendStatus(204); }); |