friend bugfix
All checks were successful
Build Images and Deploy / Update-PROD-Stack (push) Successful in 34s
All checks were successful
Build Images and Deploy / Update-PROD-Stack (push) Successful in 34s
This commit is contained in:
@@ -45,6 +45,11 @@ router.get('/', authMiddleware, asyncHandler(async (req, res) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Also get people who have shared challenges with me (auto-friends from challenges)
|
// 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(
|
const challengeFriends = await query(
|
||||||
`SELECT DISTINCT
|
`SELECT DISTINCT
|
||||||
u.id, u.username, u.email,
|
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
|
INNER JOIN challenges c ON cp.challenge_id = c.id
|
||||||
WHERE c.created_by = ? AND cp.user_id != ? AND cp.status = 'accepted'
|
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`,
|
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)]
|
[req.user.userId, req.user.userId, req.user.userId, req.user.userId, req.user.userId, req.user.userId, ...friends.map(f => f.id)]
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user