1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-07 19:32:34 +01:00

🐛 fix getPublicUser

This commit is contained in:
Flam3rboy 2021-05-30 22:14:35 +02:00
parent ea58f5b535
commit 711dc1c4d4
2 changed files with 5 additions and 9 deletions

View File

@ -75,6 +75,8 @@ router.get("/", async (req, res) => {
// @ts-ignore
delete x.user_ids;
});
// @ts-ignore
if (!x.author) x.author = { discriminator: "0000", username: "Deleted User", public_flags: 0n, avatar: null };
return x;
})

View File

@ -1,20 +1,14 @@
import { toObject, UserModel } from "@fosscord/server-util";
import { toObject, UserModel, PublicUserProjection } from "@fosscord/server-util";
import { HTTPError } from "lambert-server";
export const PublicUserProjection = {
username: true,
discriminator: true,
id: true,
public_flags: true,
avatar: true,
};
export { PublicUserProjection };
export async function getPublicUser(user_id: string, additional_fields?: any) {
const user = await UserModel.findOne(
{ id: user_id },
{
...PublicUserProjection,
...additional_fields,
...additional_fields
}
).exec();
if (!user) throw new HTTPError("User not found", 404);