refactor(admin): embed roles data in user list query and update role display
- remove separate `/zen/api/roles` fetch and `roleColorMap` state from UsersPage - update SQL query to include aggregated roles array per user via subquery - replace single role badge with multi-badge display supporting overflow indicator
This commit is contained in:
@@ -129,7 +129,15 @@ async function handleListUsers(request) {
|
||||
const quotedSortColumn = `"${sortColumn}"`;
|
||||
|
||||
const result = await query(
|
||||
`SELECT id, email, name, role, image, email_verified, created_at FROM zen_auth_users ORDER BY ${quotedSortColumn} ${order} LIMIT $1 OFFSET $2`,
|
||||
`SELECT u.id, u.email, u.name, u.role, u.image, u.email_verified, u.created_at,
|
||||
COALESCE(
|
||||
(SELECT json_agg(json_build_object('id', r.id, 'name', r.name, 'color', r.color) ORDER BY r.created_at ASC)
|
||||
FROM zen_auth_roles r
|
||||
JOIN zen_auth_user_roles ur ON ur.role_id = r.id
|
||||
WHERE ur.user_id = u.id),
|
||||
'[]'::json
|
||||
) AS roles
|
||||
FROM zen_auth_users u ORDER BY u.${quotedSortColumn} ${order} LIMIT $1 OFFSET $2`,
|
||||
[limit, offset]
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user