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,7 +60,8 @@ router.get('/', async (req, res, next) => {
query = query.orderBy('user.updatedAt', 'DESC'); query = query.orderBy('user.updatedAt', 'DESC');
break; break;
case 'displayname': case 'displayname':
query = query.orderBy( query = query
.addSelect(
`CASE WHEN (user.username IS NULL OR user.username = '') THEN ( `CASE WHEN (user.username IS NULL OR user.username = '') THEN (
CASE WHEN (user.plexUsername IS NULL OR user.plexUsername = '') THEN ( CASE WHEN (user.plexUsername IS NULL OR user.plexUsername = '') THEN (
CASE WHEN (user.jellyfinUsername IS NULL OR user.jellyfinUsername = '') THEN CASE WHEN (user.jellyfinUsername IS NULL OR user.jellyfinUsername = '') THEN
@@ -74,8 +75,9 @@ router.get('/', async (req, res, next) => {
ELSE ELSE
LOWER(user.username) LOWER(user.username)
END`, END`,
'ASC' 'displayname_sort_key'
); )
.orderBy('displayname_sort_key', 'ASC');
break; break;
case 'requests': case 'requests':
query = query query = query