summary refs log tree commit diff
path: root/src/api/routes/policies/stats.ts
blob: 5ef4c3c68289108fefc0b2980770034cb619387b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { route } from "@fosscord/api";
import { Config, getRights, Guild, Member, Message, User } from "@fosscord/util";
import { Request, Response, Router } from "express";
const router = Router();

router.get("/", route({}), async (req: Request, res: Response) => {
	if (!Config.get().security.statsWorldReadable) {
		const rights = await getRights(req.user_id);
		rights.hasThrow("VIEW_SERVER_STATS");
	}

	res.json({
		counts: {
			user: await User.count(),
			guild: await Guild.count(),
			message: await Message.count(),
			members: await Member.count(),
		}
	});
});

export default router;