From dbd9f89fbd8e5e18c1f1b869a9d7d6baf3902617 Mon Sep 17 00:00:00 2001 From: Mike Johnston Date: Fri, 30 Jan 2026 17:43:02 -0500 Subject: [PATCH] friend bugfix --- backend/src/routes/friends.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/src/routes/friends.js b/backend/src/routes/friends.js index 14b443b..e78be3a 100644 --- a/backend/src/routes/friends.js +++ b/backend/src/routes/friends.js @@ -45,6 +45,11 @@ router.get('/', authMiddleware, asyncHandler(async (req, res) => { ); // Also get people who have shared challenges with me (auto-friends from challenges) + // Build the NOT IN clause only if there are friends to exclude + const notInClause = friends.length > 0 + ? `AND u.id NOT IN (${friends.map(() => '?').join(',')})` + : ''; + const challengeFriends = await query( `SELECT DISTINCT u.id, u.username, u.email, @@ -66,7 +71,7 @@ router.get('/', authMiddleware, asyncHandler(async (req, res) => { INNER JOIN challenges c ON cp.challenge_id = c.id WHERE c.created_by = ? AND cp.user_id != ? AND cp.status = 'accepted' ) - AND u.id NOT IN (${friends.map(() => '?').join(',') || 'NULL'}) + ${notInClause} ORDER BY u.username`, [req.user.userId, req.user.userId, req.user.userId, req.user.userId, req.user.userId, req.user.userId, ...friends.map(f => f.id)] );