summary refs log tree commit diff
path: root/src/util/User.ts
blob: 0f3768cc293c66e6d9a1babc381bd7822e3dd0f1 (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);
}