Fix profile API

It should no longer send a random user(Emma/Rory) and should now just send the correct user.
This commit is contained in:
MathMan05
2025-12-29 11:00:18 -06:00
committed by Rory&
parent 16e90d228e
commit b7d359c3cd

View File

@@ -28,10 +28,11 @@ router.get("/", route({ responses: { 200: { body: "UserProfileResponse" } } }),
if (req.params.user_id === "@me") req.params.user_id = req.user_id;
const { guild_id, with_mutual_guilds, with_mutual_friends, with_mutual_friends_count } = req.query;
const { user_id } = req.params;
const user = await User.findOneOrFail({
where: {
id: req.params.id,
id: user_id,
},
relations: { connected_accounts: true },
});
@@ -41,10 +42,10 @@ router.get("/", route({ responses: { 200: { body: "UserProfileResponse" } } }),
if (with_mutual_guilds == "true") {
const requested_member = await Member.find({
where: { id: req.params.user_id },
where: { id: user_id },
});
const self_member = await Member.find({
where: { id: req.user_id },
where: { id: user_id },
});
for (const rmem of requested_member) {
@@ -71,7 +72,7 @@ router.get("/", route({ responses: { 200: { body: "UserProfileResponse" } } }),
const guild_member =
guild_id && typeof guild_id == "string"
? await Member.findOneOrFail({
where: { id: req.params.user_id, guild_id: guild_id },
where: { id: user_id, guild_id: guild_id },
relations: { roles: true },
})
: undefined;
@@ -99,8 +100,8 @@ router.get("/", route({ responses: { 200: { body: "UserProfileResponse" } } }),
let mutual_friends_count = 0;
if (with_mutual_friends == "true" || with_mutual_friends_count == "true") {
const relationshipsSelf = await Relationship.find({ where: { from_id: req.user_id, type: RelationshipType.friends } });
const relationshipsUser = await Relationship.find({ where: { from_id: req.params.user_id, type: RelationshipType.friends } });
const relationshipsSelf = await Relationship.find({ where: { from_id: user_id, type: RelationshipType.friends } });
const relationshipsUser = await Relationship.find({ where: { from_id: user_id, type: RelationshipType.friends } });
const relationshipsIntersection = relationshipsSelf.filter((r1) => relationshipsUser.some((r2) => r2.to_id === r1.to_id));
if (with_mutual_friends_count) mutual_friends_count = relationshipsIntersection.length;
if (with_mutual_friends) {