summary refs log tree commit diff
path: root/api/src/routes
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-20 21:34:33 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-20 21:34:33 +0200
commit5b3ac6dadbfec8d2a0411858dfdfa715b7ab06ee (patch)
tree47d41f14f7055ddd32d15eb64af89dfe0b2e4afb /api/src/routes
parentMerge pull request #382 from fosscord/auto-delete-relations (diff)
downloadserver-5b3ac6dadbfec8d2a0411858dfdfa715b7ab06ee.tar.xz
:bug: fix relationships
Diffstat (limited to 'api/src/routes')
-rw-r--r--api/src/routes/users/@me/relationships.ts14
1 files changed, 7 insertions, 7 deletions
diff --git a/api/src/routes/users/@me/relationships.ts b/api/src/routes/users/@me/relationships.ts
index 6ad873a6..567c734e 100644
--- a/api/src/routes/users/@me/relationships.ts
+++ b/api/src/routes/users/@me/relationships.ts
@@ -21,20 +21,20 @@ router.get("/", route({}), async (req: Request, res: Response) => {
 	const user = await User.findOneOrFail({ where: { id: req.user_id }, relations: ["relationships", "relationships.to"] });
 
 	//TODO DTO
-	const related_users = user.relationships.map(r => {
+	const related_users = user.relationships.map((r) => {
 		return {
 			id: r.to.id,
 			type: r.type,
 			nickname: null,
-			user: r.to.toPublicUser(),
-		}
-	})
+			user: r.to.toPublicUser()
+		};
+	});
 
 	return res.json(related_users);
 });
 
 export interface RelationshipPutSchema {
-	type: RelationshipType;
+	type?: RelationshipType;
 }
 
 router.put("/:id", route({ body: "RelationshipPutSchema" }), async (req: Request, res: Response) => {
@@ -42,7 +42,7 @@ router.put("/:id", route({ body: "RelationshipPutSchema" }), async (req: Request
 		req,
 		res,
 		await User.findOneOrFail({ id: req.params.id }, { relations: ["relationships", "relationships.to"], select: userProjection }),
-		req.body.type
+		req.body.type ?? RelationshipType.friends
 	);
 });
 
@@ -59,7 +59,7 @@ router.post("/", route({ body: "RelationshipPostSchema" }), async (req: Request,
 			relations: ["relationships", "relationships.to"],
 			select: userProjection,
 			where: {
-				discriminator: String(req.body.discriminator).padStart(4, '0'), //Discord send the discriminator as integer, we need to add leading zeroes
+				discriminator: String(req.body.discriminator).padStart(4, "0"), //Discord send the discriminator as integer, we need to add leading zeroes
 				username: req.body.username
 			}
 		}),