summary refs log tree commit diff
path: root/api/src/routes/guilds
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-20 21:49:42 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-20 21:49:42 +0200
commit5cec6e43d4e193616458a7e9c74a486ceade7e93 (patch)
treed0728474d103bcd6743e365828b342b750902c33 /api/src/routes/guilds
parent:sparkles: route middleware test option (diff)
parent:bug: fix relationships (diff)
downloadserver-5cec6e43d4e193616458a7e9c74a486ceade7e93.tar.xz
Merge branch 'master' into unittests
Diffstat (limited to 'api/src/routes/guilds')
-rw-r--r--api/src/routes/guilds/#guild_id/delete.ts12
-rw-r--r--api/src/routes/guilds/#guild_id/index.ts3
-rw-r--r--api/src/routes/guilds/index.ts4
3 files changed, 4 insertions, 15 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);
 });
 
diff --git a/api/src/routes/guilds/#guild_id/index.ts b/api/src/routes/guilds/#guild_id/index.ts
index 63000b84..d8ee86ff 100644
--- a/api/src/routes/guilds/#guild_id/index.ts
+++ b/api/src/routes/guilds/#guild_id/index.ts
@@ -1,8 +1,7 @@
 import { Request, Response, Router } from "express";
-import { emitEvent, getPermission, Guild, GuildUpdateEvent, Member } from "@fosscord/util";
+import { emitEvent, getPermission, Guild, GuildUpdateEvent, handleFile, Member } from "@fosscord/util";
 import { HTTPError } from "lambert-server";
 import { route } from "@fosscord/api";
-import { handleFile } from "@fosscord/api";
 import "missing-native-js-functions";
 import { GuildCreateSchema } from "../index";
 
diff --git a/api/src/routes/guilds/index.ts b/api/src/routes/guilds/index.ts
index 2e68d953..abde147d 100644
--- a/api/src/routes/guilds/index.ts
+++ b/api/src/routes/guilds/index.ts
@@ -1,7 +1,6 @@
 import { Router, Request, Response } from "express";
-import { Role, Guild, Snowflake, Config, User, Member, Channel } from "@fosscord/util";
+import { Role, Guild, Snowflake, Config, Member, Channel, DiscordApiErrors, handleFile } from "@fosscord/util";
 import { route } from "@fosscord/api";
-import { DiscordApiErrors } from "@fosscord/util";
 import { ChannelModifySchema } from "../channels/#channel_id";
 
 const router: Router = Router();
@@ -34,6 +33,7 @@ router.post("/", route({ body: "GuildCreateSchema" }), async (req: Request, res:
 
 	await Guild.insert({
 		name: body.name,
+		icon: await handleFile(`/icons/${guild_id}`, body.icon as string),
 		region: Config.get().regions.default,
 		owner_id: req.user_id,
 		afk_timeout: 300,