1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-10 12:42:44 +01:00

🐛 fix user projection

This commit is contained in:
Flam3rboy 2021-10-05 19:52:42 +02:00
parent b76961657e
commit ce63639090
7 changed files with 13 additions and 6 deletions

View File

@ -79,7 +79,7 @@ router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Re
if (!register.allowMultipleAccounts) {
// TODO: check if fingerprint was eligible generated
const exists = await User.findOne({ where: { fingerprints: body.fingerprint } });
const exists = await User.findOne({ where: { fingerprints: body.fingerprint }, select: ["id"] });
if (exists) {
throw FieldErrors({
@ -109,7 +109,7 @@ router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Re
}
// check if there is already an account with this email
const exists = await User.findOneOrFail({ email: email }).catch((e) => {});
const exists = await User.findOne({ email: email });
if (exists) {
throw FieldErrors({

View File

@ -7,7 +7,7 @@ import { HTTPError } from "lambert-server";
const router = Router();
router.post("/", route({}), async (req: Request, res: Response) => {
const user = await User.findOneOrFail({ id: req.user_id }); //User object
const user = await User.findOneOrFail({ where: { id: req.user_id }, select: ["data"] }); //User object
let correctpass = true;
if (user.data.hash) {

View File

@ -6,7 +6,7 @@ import bcrypt from "bcrypt";
const router = Router();
router.post("/", route({}), async (req: Request, res: Response) => {
const user = await User.findOneOrFail({ id: req.user_id }); //User object
const user = await User.findOneOrFail({ where: { id: req.user_id }, select: ["data"] }); //User object
let correctpass = true;
if (user.data.hash) {

View File

@ -18,7 +18,11 @@ const router = Router();
const userProjection: (keyof User)[] = ["relationships", ...PublicUserProjection];
router.get("/", route({}), async (req: Request, res: Response) => {
const user = await User.findOneOrFail({ where: { id: req.user_id }, relations: ["relationships", "relationships.to"] });
const user = await User.findOneOrFail({
where: { id: req.user_id },
relations: ["relationships", "relationships.to"],
select: ["relationships"]
});
//TODO DTO
const related_users = user.relationships.map((r) => {

View File

@ -21,6 +21,7 @@ import {
PublicMember,
ChannelType,
PublicUser,
PrivateUserProjection,
} from "@fosscord/util";
import { setupListener } from "../listener/listener";
import { IdentifySchema } from "../schema/Identify";
@ -111,6 +112,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
const user = await User.findOneOrFail({
where: { id: this.user_id },
relations: ["relationships", "relationships.to"],
select: [...PrivateUserProjection, "relationships"],
});
if (!user) return this.close(CLOSECODES.Authentication_failed);

View File

@ -203,7 +203,7 @@ export class Channel extends BaseClass {
static async createDMChannel(recipients: string[], creator_user_id: string, name?: string) {
recipients = recipients.unique().filter((x) => x !== creator_user_id);
const otherRecipientsUsers = await User.find({ where: recipients.map((x) => ({ id: x })) });
const otherRecipientsUsers = await User.find({ where: recipients.map((x) => ({ id: x })), select: ["id"] });
// TODO: check config for max number of recipients
if (otherRecipientsUsers.length !== recipients.length) {

View File

@ -29,6 +29,7 @@ export enum PrivateUserEnum {
premium,
premium_type,
disabled,
settings,
// locale
}
export type PrivateUserKeys = keyof typeof PrivateUserEnum | PublicUserKeys;