summary refs log tree commit diff
path: root/api/src/routes/discoverable-guilds.ts
blob: 509abc9e7126e2766b7b749b1a4e54c4b8bb6d5f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { Guild, Config } from "@fosscord/util";

import { Router, Request, Response } from "express";
import { route } from "@fosscord/api";


const router = Router();

router.get("/", route({}), async (req: Request, res: Response) => {
	const { limit } = req.params;
	var showAllGuilds = Config.get().guild.showAllGuildsInDiscovery;

	// ! 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 guilds = showAllGuilds ? await Guild.find({take: Math.abs(Number(limit))}) : await Guild.find({ where: `"features" LIKE '%COMMUNITY%'`, take: Math.abs(Number(limit)) });
	res.send({ guilds: guilds });
});

export default router;