summary refs log tree commit diff
path: root/src/util/User.ts
blob: 1b13e1530e3d4a2c3e37beabdf6d85e92d5ee8d3 (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 { UserModel } from "fosscord-server-util";
import { HTTPError } from "lambert-server";

export const PublicUserProjection = {
	username: true,
	discriminator: true,
	id: true,
	public_flags: true,
	avatar: true,
};

export async function getPublicUser(user_id: bigint, additional_fields?: any) {
	const user = await UserModel.findOne(
		{ id: user_id },
		{
			...PublicUserProjection,
			...additional_fields,
		}
	).exec();
	if (!user) throw new HTTPError("User not found", 404);
	return user;
}