summary refs log tree commit diff
path: root/api/src/routes
diff options
context:
space:
mode:
authorFeatyre <twooter.0g179@simplelogin.co>2022-01-24 07:21:48 +0000
committerFeatyre <twooter.0g179@simplelogin.co>2022-01-24 07:21:48 +0000
commite3f20f849d089493328314ad7d7518eaea3d862a (patch)
tree294774d318a7baf80f271e71a4346d26523f432d /api/src/routes
parentMerge branch 'fosscord:master' into master (diff)
downloadserver-e3f20f849d089493328314ad7d7518eaea3d862a.tar.xz
category + discovery + custom status fix, new config
Diffstat (limited to 'api/src/routes')
-rw-r--r--api/src/routes/discoverable-guilds.ts29
-rw-r--r--api/src/routes/discovery.ts (renamed from api/src/routes/categories.ts)4
-rw-r--r--api/src/routes/guild-recommendations.ts2
3 files changed, 19 insertions, 16 deletions
diff --git a/api/src/routes/discoverable-guilds.ts b/api/src/routes/discoverable-guilds.ts
index a4559b59..8b7d343f 100644
--- a/api/src/routes/discoverable-guilds.ts
+++ b/api/src/routes/discoverable-guilds.ts
@@ -6,26 +6,29 @@ import { route } from "@fosscord/api";
 const router = Router();
 
 router.get("/", route({}), async (req: Request, res: Response) => {
-	const { limit, categories } = req.query;
-	var showAllGuilds = Config.get().guild.showAllGuildsInDiscovery;
+	const { offset, limit, categories } = req.query;
+	var showAllGuilds = Config.get().guild.discovery.showAllGuilds;
+	var configLimit = Config.get().guild.discovery.limit;
 	// ! this only works using SQL querys
 	// TODO: implement this with default typeorm query
 	// const guilds = await Guild.find({ where: { features: "DISCOVERABLE" } }); //, take: Math.abs(Number(limit)) });
 	let guilds;
 	let total;
-	switch (categories) {
-		case "1":
-			guilds = showAllGuilds
-				? await Guild.find({ take: Math.abs(Number(limit || 24)) })
-				: await Guild.find({ where: `"primary_category_id" = 1 AND "features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || 24)) });
-			total = guilds.length;
-		default:
-			guilds = showAllGuilds
-				? await Guild.find({ take: Math.abs(Number(limit || 24)) })
-				: await Guild.find({ where: `"features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || 24)) });
+	if (categories == undefined) {
+		guilds = showAllGuilds
+			? await Guild.find({ take: Math.abs(Number(limit || configLimit)) })
+			: await Guild.find({ where: `"features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit || configLimit)) });
+		total = guilds.length;
+	} else {
+		guilds = showAllGuilds
+				? await Guild.find({ where: `"primary_category_id" = ${categories}`, take: Math.abs(Number(limit || configLimit)) })
+				: await Guild.find({
+						where: `"primary_category_id" = ${categories} AND "features" LIKE '%COMMUNITY%'`,
+						take: Math.abs(Number(limit || configLimit))
+				  });
 			total = guilds.length;
 	}
-	res.send({ total: total, guilds: guilds, offset: 0, limit: limit});
+	res.send({ total: total, guilds: guilds, offset: Number(offset || Config.get().guild.discovery.offset), limit: Number(limit || configLimit) });
 });
 
 export default router;
diff --git a/api/src/routes/categories.ts b/api/src/routes/discovery.ts
index 58322676..067dd442 100644
--- a/api/src/routes/categories.ts
+++ b/api/src/routes/discovery.ts
@@ -3,7 +3,7 @@ import { route } from "@fosscord/api";
 
 const router = Router();
 
-router.get("/", route({}), (req: Request, res: Response) => {
+router.get("/categories", route({}), (req: Request, res: Response) => {
 	// TODO:
 	// Load categories from db instead
 
@@ -21,7 +21,7 @@ router.get("/", route({}), (req: Request, res: Response) => {
 				}
 	}
 
-	res.json(out).status(200);
+	res.send(out);
 });
 
 export default router;
diff --git a/api/src/routes/guild-recommendations.ts b/api/src/routes/guild-recommendations.ts
index 47017a6f..ecc5e546 100644
--- a/api/src/routes/guild-recommendations.ts
+++ b/api/src/routes/guild-recommendations.ts
@@ -7,7 +7,7 @@ const router = Router();
 
 router.get("/", route({}), async (req: Request, res: Response) => {
 	const { limit, personalization_disabled } = req.query;
-	var showAllGuilds = Config.get().guild.showAllGuildsInDiscovery;
+	var showAllGuilds = Config.get().guild.discovery.showAllGuilds;
 	// ! this only works using SQL querys
 	// TODO: implement this with default typeorm query
 	// const guilds = await Guild.find({ where: { features: "DISCOVERABLE" } }); //, take: Math.abs(Number(limit)) });