23 lines
526 B
TypeScript
23 lines
526 B
TypeScript
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);
|
|
}
|