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-12 21:21:08 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-12 21:21:08 +0200
commitbffeb4af0d34546747e5d1941da3544d2482f3e0 (patch)
tree4979a07ddeaf8df6287dd5ebb66614c9476975e9 /api/src/routes/guilds
parent:bug: fix gateway (diff)
downloadserver-bffeb4af0d34546747e5d1941da3544d2482f3e0.tar.xz
:construction: :sparkles: new body parser (bans route)
Diffstat (limited to 'api/src/routes/guilds')
-rw-r--r--api/src/routes/guilds/#guild_id/bans.ts25
1 files changed, 10 insertions, 15 deletions
diff --git a/api/src/routes/guilds/#guild_id/bans.ts b/api/src/routes/guilds/#guild_id/bans.ts
index 86bff6b4..41a97b6a 100644
--- a/api/src/routes/guilds/#guild_id/bans.ts
+++ b/api/src/routes/guilds/#guild_id/bans.ts
@@ -1,19 +1,18 @@
 import { Request, Response, Router } from "express";
 import { emitEvent, getPermission, GuildBanAddEvent, GuildBanRemoveEvent, Guild, Ban, User, Member } from "@fosscord/util";
 import { HTTPError } from "lambert-server";
-import { getIpAdress, check } from "@fosscord/api";
+import { getIpAdress, check, route } from "@fosscord/api";
 import { BanCreateSchema } from "@fosscord/api/schema/Ban";
 
 const router: Router = Router();
-
-router.get("/", async (req: Request, res: Response) => {
+router.get("/", route({ permission: "BAN_MEMBERS" }), async (req: Request, res: Response) => {
 	const { guild_id } = req.params;
 
 	var bans = await Ban.find({ guild_id: guild_id });
 	return res.json(bans);
 });
 
-router.get("/:user", async (req: Request, res: Response) => {
+router.get("/:user", route({ permission: "BAN_MEMBERS" }), async (req: Request, res: Response) => {
 	const { guild_id } = req.params;
 	const user_id = req.params.ban;
 
@@ -21,15 +20,14 @@ router.get("/:user", async (req: Request, res: Response) => {
 	return res.json(ban);
 });
 
-router.put("/:user_id", check(BanCreateSchema), async (req: Request, res: Response) => {
+router.put("/:user_id", route({ body: "BanCreateSchema", permission: "BAN_MEMBERS" }), async (req: Request, res: Response) => {
 	const { guild_id } = req.params;
 	const banned_user_id = req.params.user_id;
 
 	const banned_user = await User.getPublicUser(banned_user_id);
-	const perms = await getPermission(req.user_id, guild_id);
-	perms.hasThrow("BAN_MEMBERS");
+
 	if (req.user_id === banned_user_id) throw new HTTPError("You can't ban yourself", 400);
-	if (perms.cache.guild?.owner_id === banned_user_id) throw new HTTPError("You can't ban the owner", 400);
+	if (req.permission?.cache.guild?.owner_id === banned_user_id) throw new HTTPError("You can't ban the owner", 400);
 
 	const ban = new Ban({
 		user_id: banned_user_id,
@@ -55,17 +53,14 @@ router.put("/:user_id", check(BanCreateSchema), async (req: Request, res: Respon
 	return res.json(ban);
 });
 
-router.delete("/:user_id", async (req: Request, res: Response) => {
-	var { guild_id } = req.params;
-	var banned_user_id = req.params.user_id;
+router.delete("/:user_id", route({ permission: "BAN_MEMBERS" }), async (req: Request, res: Response) => {
+	const { guild_id, user_id } = req.params;
 
-	const banned_user = await User.getPublicUser(banned_user_id);
-	const perms = await getPermission(req.user_id, guild_id);
-	perms.hasThrow("BAN_MEMBERS");
+	const banned_user = await User.getPublicUser(user_id);
 
 	await Promise.all([
 		Ban.delete({
-			user_id: banned_user_id,
+			user_id: user_id,
 			guild_id
 		}),