summary refs log tree commit diff
path: root/api/src/routes/guilds/#guild_id/members
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-13 17:51:16 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-13 17:51:16 +0200
commitdcc3ae6a14fad39bfc493fdb3e2fa285151e3bde (patch)
treecf8811289283d854e74611fa406db1c17a0045d1 /api/src/routes/guilds/#guild_id/members
parent:bug: fix In() query (diff)
downloadserver-dcc3ae6a14fad39bfc493fdb3e2fa285151e3bde.tar.xz
:art: remove unused imports
Diffstat (limited to 'api/src/routes/guilds/#guild_id/members')
-rw-r--r--api/src/routes/guilds/#guild_id/members/#member_id/index.ts2
-rw-r--r--api/src/routes/guilds/#guild_id/members/index.ts24
2 files changed, 9 insertions, 17 deletions
diff --git a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts b/api/src/routes/guilds/#guild_id/members/#member_id/index.ts
index 1708b7eb..ab489743 100644
--- a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts
+++ b/api/src/routes/guilds/#guild_id/members/#member_id/index.ts
@@ -1,7 +1,7 @@
 import { Request, Response, Router } from "express";
 import { Member, getPermission, Role, GuildMemberUpdateEvent, emitEvent } from "@fosscord/util";
 import { HTTPError } from "lambert-server";
-import { check, route } from "@fosscord/api";
+import { route } from "@fosscord/api";
 
 const router = Router();
 
diff --git a/api/src/routes/guilds/#guild_id/members/index.ts b/api/src/routes/guilds/#guild_id/members/index.ts
index 335f21c7..386276c8 100644
--- a/api/src/routes/guilds/#guild_id/members/index.ts
+++ b/api/src/routes/guilds/#guild_id/members/index.ts
@@ -1,7 +1,8 @@
 import { Request, Response, Router } from "express";
 import { Guild, Member, PublicMemberProjection } from "@fosscord/util";
-import { instanceOf, Length, route } from "@fosscord/api";
+import { route } from "@fosscord/api";
 import { MoreThan } from "typeorm";
+import { HTTPError } from "lambert-server";
 
 const router = Router();
 
@@ -11,26 +12,17 @@ const router = Router();
 
 router.get("/", route({}), async (req: Request, res: Response) => {
 	const { guild_id } = req.params;
-	const guild = await Guild.findOneOrFail({ id: guild_id });
-	await Member.IsInGuildOrFail(req.user_id, guild_id);
-
-	try {
-		instanceOf({ $limit: new Length(Number, 1, 1000), $after: String }, req.query, {
-			path: "query",
-			req,
-			ref: { obj: null, key: "" }
-		});
-	} catch (error) {
-		return res.status(400).json({ code: 50035, message: "Invalid Query", success: false, errors: error });
-	}
-
-	const { limit, after } = (<unknown>req.query) as { limit?: number; after?: string };
+	const limit = Number(req.query.limit) || 1;
+	if (limit > 1000 || limit < 1) throw new HTTPError("Limit must be between 1 and 1000");
+	const after = `${req.query.after}`;
 	const query = after ? { id: MoreThan(after) } : {};
 
+	await Member.IsInGuildOrFail(req.user_id, guild_id);
+
 	const members = await Member.find({
 		where: { guild_id, ...query },
 		select: PublicMemberProjection,
-		take: limit || 1,
+		take: limit,
 		order: { id: "ASC" }
 	});