summary refs log tree commit diff
path: root/api/src/routes/users
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-31 17:58:47 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-31 17:58:47 +0200
commitcc8c5359ce1c863acfb7f60ef2cf02d5f900305f (patch)
treeaec266d05c66eb10864391766cceb7142b904504 /api/src/routes/users
parent:sparkles: channel recipients (diff)
downloadserver-cc8c5359ce1c863acfb7f60ef2cf02d5f900305f.tar.xz
:bug: db query fixes
Diffstat (limited to 'api/src/routes/users')
-rw-r--r--api/src/routes/users/@me/disable.ts2
-rw-r--r--api/src/routes/users/@me/index.ts2
-rw-r--r--api/src/routes/users/@me/relationships.ts12
3 files changed, 8 insertions, 8 deletions
diff --git a/api/src/routes/users/@me/disable.ts b/api/src/routes/users/@me/disable.ts
index ed1dedcc..7b8a130c 100644
--- a/api/src/routes/users/@me/disable.ts
+++ b/api/src/routes/users/@me/disable.ts
@@ -5,7 +5,7 @@ import bcrypt from "bcrypt";
 const router = Router();
 
 router.post("/", async (req: Request, res: Response) => {
-	const user = await User.findOneOrFail(req.user_id); //User object
+	const user = await User.findOneOrFail({ id: req.user_id }); //User object
 	let correctpass = true;
 
 	if (user.data.hash) {
diff --git a/api/src/routes/users/@me/index.ts b/api/src/routes/users/@me/index.ts
index 274cfb24..d5a5723c 100644
--- a/api/src/routes/users/@me/index.ts
+++ b/api/src/routes/users/@me/index.ts
@@ -37,7 +37,7 @@ router.patch("/", check(UserModifySchema), async (req: Request, res: Response) =
 	if (body.avatar) body.avatar = await handleFile(`/avatars/${req.user_id}`, body.avatar as string);
 	if (body.banner) body.banner = await handleFile(`/banners/${req.user_id}`, body.banner as string);
 
-	const user = await new User({ ...body }, { id: req.user_id }).save();
+	const user = await new User({ ...body, id: req.user_id }).save();
 	// TODO: dispatch user update event
 
 	res.json(user);
diff --git a/api/src/routes/users/@me/relationships.ts b/api/src/routes/users/@me/relationships.ts
index 1a89b110..0b864d88 100644
--- a/api/src/routes/users/@me/relationships.ts
+++ b/api/src/routes/users/@me/relationships.ts
@@ -26,7 +26,7 @@ async function updateRelationship(req: Request, res: Response, friend: User, typ
 	const id = friend.id;
 	if (id === req.user_id) throw new HTTPError("You can't add yourself as a friend");
 
-	const user = await User.findOneOrFail(req.user_id, { relations: ["relationships"], select: userProjection });
+	const user = await User.findOneOrFail({ id: req.user_id }, { relations: ["relationships"], select: userProjection });
 
 	var relationship = user.relationships.find((x) => x.id === id);
 	const friendRequest = friend.relationships.find((x) => x.id === req.user_id);
@@ -67,8 +67,8 @@ async function updateRelationship(req: Request, res: Response, friend: User, typ
 		return res.sendStatus(204);
 	}
 
-	var incoming_relationship = new Relationship({ nickname: undefined, type: RelationshipType.incoming }, { id: req.user_id });
-	var outgoing_relationship = new Relationship({ nickname: undefined, type: RelationshipType.outgoing }, { id });
+	var incoming_relationship = new Relationship({ nickname: undefined, type: RelationshipType.incoming, id: req.user_id });
+	var outgoing_relationship = new Relationship({ nickname: undefined, type: RelationshipType.outgoing, id });
 
 	if (friendRequest) {
 		if (friendRequest.type === RelationshipType.blocked) throw new HTTPError("The user blocked you");
@@ -113,7 +113,7 @@ router.put("/:id", check({ $type: new Length(Number, 1, 4) }), async (req: Reque
 	return await updateRelationship(
 		req,
 		res,
-		await User.findOneOrFail(req.params.id, { relations: ["relationships"], select: userProjection }),
+		await User.findOneOrFail({ id: req.params.id }, { relations: ["relationships"], select: userProjection }),
 		req.body.type
 	);
 });
@@ -135,8 +135,8 @@ router.delete("/:id", async (req: Request, res: Response) => {
 	const { id } = req.params;
 	if (id === req.user_id) throw new HTTPError("You can't remove yourself as a friend");
 
-	const user = await User.findOneOrFail(req.user_id, { select: userProjection, relations: ["relationships"] });
-	const friend = await User.findOneOrFail(id, { select: userProjection, relations: ["relationships"] });
+	const user = await User.findOneOrFail({ id: req.user_id }, { select: userProjection, relations: ["relationships"] });
+	const friend = await User.findOneOrFail({ id: id }, { select: userProjection, relations: ["relationships"] });
 
 	const relationship = user.relationships.find((x) => x.id === id);
 	const friendRequest = friend.relationships.find((x) => x.id === req.user_id);