Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/api/routes/users/#user_id/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
});
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Loading