summary refs log tree commit diff
path: root/api/src/util/User.ts
blob: 392c71017bfde104d4fe015f62d790a061b6e3f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { toObject, UserModel, PublicUserProjection } from "@fosscord/util";
import { HTTPError } from "lambert-server";

export { PublicUserProjection };

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);
}