fix(users): correct user list for Postgres (#1443)

PostgreSQL requires that the ORDER BY expression must appear in the SELECT list when using DISTINCT.
Since we were using a computed expression in the ORDER BY clause, we need to include it in the
SELECT list as well.

re #1333
This commit is contained in:
Gauthier
2025-03-10 23:59:42 +01:00
committed by GitHub
parent 0113612ced
commit 5b998bef82

View File

@@ -60,22 +60,24 @@ router.get('/', async (req, res, next) => {
query = query.orderBy('user.updatedAt', 'DESC');
break;
case 'displayname':
query = query.orderBy(
`CASE WHEN (user.username IS NULL OR user.username = '') THEN (
CASE WHEN (user.plexUsername IS NULL OR user.plexUsername = '') THEN (
CASE WHEN (user.jellyfinUsername IS NULL OR user.jellyfinUsername = '') THEN
"user"."email"
ELSE
LOWER(user.jellyfinUsername)
END)
ELSE
LOWER(user.jellyfinUsername)
END)
ELSE
LOWER(user.username)
END`,
'ASC'
);
query = query
.addSelect(
`CASE WHEN (user.username IS NULL OR user.username = '') THEN (
CASE WHEN (user.plexUsername IS NULL OR user.plexUsername = '') THEN (
CASE WHEN (user.jellyfinUsername IS NULL OR user.jellyfinUsername = '') THEN
"user"."email"
ELSE
LOWER(user.jellyfinUsername)
END)
ELSE
LOWER(user.jellyfinUsername)
END)
ELSE
LOWER(user.username)
END`,
'displayname_sort_key'
)
.orderBy('displayname_sort_key', 'ASC');
break;
case 'requests':
query = query