🐛 fix user projection
This commit is contained in:
parent
b76961657e
commit
ce63639090
@ -79,7 +79,7 @@ router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Re
|
|||||||
|
|
||||||
if (!register.allowMultipleAccounts) {
|
if (!register.allowMultipleAccounts) {
|
||||||
// TODO: check if fingerprint was eligible generated
|
// 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) {
|
if (exists) {
|
||||||
throw FieldErrors({
|
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
|
// 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) {
|
if (exists) {
|
||||||
throw FieldErrors({
|
throw FieldErrors({
|
||||||
|
@ -7,7 +7,7 @@ import { HTTPError } from "lambert-server";
|
|||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post("/", route({}), async (req: Request, res: Response) => {
|
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;
|
let correctpass = true;
|
||||||
|
|
||||||
if (user.data.hash) {
|
if (user.data.hash) {
|
||||||
|
@ -6,7 +6,7 @@ import bcrypt from "bcrypt";
|
|||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post("/", route({}), async (req: Request, res: Response) => {
|
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;
|
let correctpass = true;
|
||||||
|
|
||||||
if (user.data.hash) {
|
if (user.data.hash) {
|
||||||
|
@ -18,7 +18,11 @@ const router = Router();
|
|||||||
const userProjection: (keyof User)[] = ["relationships", ...PublicUserProjection];
|
const userProjection: (keyof User)[] = ["relationships", ...PublicUserProjection];
|
||||||
|
|
||||||
router.get("/", route({}), async (req: Request, res: Response) => {
|
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
|
//TODO DTO
|
||||||
const related_users = user.relationships.map((r) => {
|
const related_users = user.relationships.map((r) => {
|
||||||
|
@ -21,6 +21,7 @@ import {
|
|||||||
PublicMember,
|
PublicMember,
|
||||||
ChannelType,
|
ChannelType,
|
||||||
PublicUser,
|
PublicUser,
|
||||||
|
PrivateUserProjection,
|
||||||
} from "@fosscord/util";
|
} from "@fosscord/util";
|
||||||
import { setupListener } from "../listener/listener";
|
import { setupListener } from "../listener/listener";
|
||||||
import { IdentifySchema } from "../schema/Identify";
|
import { IdentifySchema } from "../schema/Identify";
|
||||||
@ -111,6 +112,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
|
|||||||
const user = await User.findOneOrFail({
|
const user = await User.findOneOrFail({
|
||||||
where: { id: this.user_id },
|
where: { id: this.user_id },
|
||||||
relations: ["relationships", "relationships.to"],
|
relations: ["relationships", "relationships.to"],
|
||||||
|
select: [...PrivateUserProjection, "relationships"],
|
||||||
});
|
});
|
||||||
if (!user) return this.close(CLOSECODES.Authentication_failed);
|
if (!user) return this.close(CLOSECODES.Authentication_failed);
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ export class Channel extends BaseClass {
|
|||||||
|
|
||||||
static async createDMChannel(recipients: string[], creator_user_id: string, name?: string) {
|
static async createDMChannel(recipients: string[], creator_user_id: string, name?: string) {
|
||||||
recipients = recipients.unique().filter((x) => x !== creator_user_id);
|
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
|
// TODO: check config for max number of recipients
|
||||||
if (otherRecipientsUsers.length !== recipients.length) {
|
if (otherRecipientsUsers.length !== recipients.length) {
|
||||||
|
@ -29,6 +29,7 @@ export enum PrivateUserEnum {
|
|||||||
premium,
|
premium,
|
||||||
premium_type,
|
premium_type,
|
||||||
disabled,
|
disabled,
|
||||||
|
settings,
|
||||||
// locale
|
// locale
|
||||||
}
|
}
|
||||||
export type PrivateUserKeys = keyof typeof PrivateUserEnum | PublicUserKeys;
|
export type PrivateUserKeys = keyof typeof PrivateUserEnum | PublicUserKeys;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user