diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-03 05:04:13 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-03 05:04:13 +0200 |
commit | bac6d570bf1b0dbfdb52c06ef5358a7cb76aca96 (patch) | |
tree | 28f35a1ec1dc4879b9bb5752e110531ec192db5f | |
parent | :bug: fix#310 (diff) | |
download | server-bac6d570bf1b0dbfdb52c06ef5358a7cb76aca96.tar.xz |
:zap: simplify permissions query
-rw-r--r-- | util/src/util/Permissions.ts | 14 |
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 |