summary refs log tree commit diff
path: root/src/util/User.ts
blob: 0521364293978766eaa901aee6aad8dda88c997c (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 { toObject, 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: string, 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 toObject(user);
}