From 3e6d1103bcb121390116ed9d2b200806da0f85d9 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Fri, 23 Apr 2021 00:15:38 +0200 Subject: :art: clean up permission checks to use .hasThrow() --- src/routes/guilds/#guild_id/bans.ts | 6 ++---- src/routes/guilds/#guild_id/index.ts | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'src/routes/guilds') diff --git a/src/routes/guilds/#guild_id/bans.ts b/src/routes/guilds/#guild_id/bans.ts index f0e3804a..f84950f9 100644 --- a/src/routes/guilds/#guild_id/bans.ts +++ b/src/routes/guilds/#guild_id/bans.ts @@ -35,7 +35,7 @@ router.post("/:user_id", check(BanCreateSchema), async (req: Request, res: Respo const banned_user = await getPublicUser(banned_user_id); const perms = await getPermission(req.user_id, guild_id); - if (!perms.has("BAN_MEMBERS")) throw new HTTPError("You don't have the permission to ban members", 403); + perms.hasThrow("BAN_MEMBERS"); if (req.user_id === banned_user_id) throw new HTTPError("You can't ban yourself", 400); await removeMember(banned_user_id, guild_id); @@ -69,9 +69,7 @@ router.delete("/:user_id", async (req: Request, res: Response) => { if (!guild) throw new HTTPError("Guild not found", 404); const perms = await getPermission(req.user_id, guild_id); - if (!perms.has("BAN_MEMBERS")) { - throw new HTTPError("No permissions", 403); - } + perms.hasThrow("BAN_MEMBERS"); await BanModel.deleteOne({ user_id: banned_user_id, diff --git a/src/routes/guilds/#guild_id/index.ts b/src/routes/guilds/#guild_id/index.ts index 96861e48..2a7d9b38 100644 --- a/src/routes/guilds/#guild_id/index.ts +++ b/src/routes/guilds/#guild_id/index.ts @@ -41,7 +41,7 @@ router.patch("/", check(GuildUpdateSchema), async (req: Request, res: Response) // TODO: guild update check image const perms = await getPermission(req.user_id, guild_id); - if (!perms.has("MANAGE_GUILD")) throw new HTTPError("You do not have the MANAGE_GUILD permission", 401); + perms.hasThrow("MANAGE_GUILD"); const guild = await GuildModel.findOneAndUpdate({ id: guild_id }, body) .populate({ path: "joined_at", match: { id: req.user_id } }) -- cgit 1.4.1