summary refs log tree commit diff
path: root/util/src
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-03 05:04:13 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-03 05:04:13 +0200
commit0c1fe5b068089eff4e5b622d8001d34453e1656a (patch)
treef20a9f39f4487b539a390786c166e6eccff447e3 /util/src
parent:bug: fix#310 (diff)
downloadserver-0c1fe5b068089eff4e5b622d8001d34453e1656a.tar.xz
:zap: simplify permissions query
Diffstat (limited to 'util/src')
-rw-r--r--util/src/util/Permissions.ts14
1 files changed, 11 insertions, 3 deletions
diff --git a/util/src/util/Permissions.ts b/util/src/util/Permissions.ts
index fcf1546b..a5da377b 100644
--- a/util/src/util/Permissions.ts
+++ b/util/src/util/Permissions.ts
@@ -212,15 +212,23 @@ export async function getPermission(user_id?: string, guild_id?: string, channel
 	var guild: Guild | undefined;
 
 	if (channel_id) {
-		channel = await Channel.findOneOrFail({ id: channel_id });
+		channel = await Channel.findOneOrFail({
+			where: { id: channel_id },
+			relations: ["recipients"],
+			select: ["id", "recipients", "permission_overwrites", "owner_id", "guild_id"],
+		});
 		if (channel.guild_id) guild_id = channel.guild_id; // derive guild_id from the channel
 	}
 
 	if (guild_id) {
-		guild = await Guild.findOneOrFail({ id: guild_id });
+		guild = await Guild.findOneOrFail({ where: { id: guild_id }, select: ["id", "owner_id"] });
 		if (guild.owner_id === user_id) return new Permissions(Permissions.FLAGS.ADMINISTRATOR);
 
-		member = await Member.findOneOrFail({ where: { guild_id, user_id }, relations: ["roles"] });
+		member = await Member.findOneOrFail({
+			where: { guild_id, user_id },
+			relations: ["roles"],
+			select: ["id", "roles"],
+		});
 	}
 
 	// TODO: remove guild.roles and convert recipient_ids to recipients