summary refs log tree commit diff
path: root/src/api/routes/guild-recommendations.ts
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-08-22 22:16:11 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-08-22 22:16:11 +1000
commit8720744091e71efe0b2e5f88956e1e0a2e9ef702 (patch)
treef00521f59f3c2ece7e790f2d0b8469c051586a92 /src/api/routes/guild-recommendations.ts
parentActually respect with_mutual_guilds (diff)
parentMerge remote-tracking branch 'Puyodead1/patch/prettier-config' into staging (diff)
downloadserver-8720744091e71efe0b2e5f88956e1e0a2e9ef702.tar.xz
Merge remote-tracking branch 'upstream/staging' into fix/sendMemberInProfile
Diffstat (limited to 'src/api/routes/guild-recommendations.ts')
-rw-r--r--src/api/routes/guild-recommendations.ts24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/api/routes/guild-recommendations.ts b/src/api/routes/guild-recommendations.ts
new file mode 100644
index 00000000..bd0140d6
--- /dev/null
+++ b/src/api/routes/guild-recommendations.ts
@@ -0,0 +1,24 @@
+import { Guild, Config } from "@fosscord/util";
+
+import { Router, Request, Response } from "express";
+import { route } from "..";
+import {Like} from "typeorm"
+
+const router = Router();
+
+router.get("/", route({}), async (req: Request, res: Response) => {
+	const { limit, personalization_disabled } = req.query;
+	let 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)) });
+
+	const genLoadId = (size: Number) => [...Array(size)].map(() => Math.floor(Math.random() * 16).toString(16)).join('');
+
+	const guilds = showAllGuilds
+		? await Guild.find({ take: Math.abs(Number(limit || 24)) })
+		: await Guild.find({ where: { features: Like('%DISCOVERABLE%') }, take: Math.abs(Number(limit || 24)) });
+	res.send({ recommended_guilds: guilds, load_id: `server_recs/${genLoadId(32)}`}).status(200);
+});
+
+export default router;