push to maple-street

This commit is contained in:
Tiel Coder
2026-11-20 04:07:02 +00:00
parent 2cec220a24
commit 5adf1cef1f
345 changed files with 86105 additions and 1079 deletions
+46
View File
@@ -0,0 +1,46 @@
/**
* Admin read models — the people list behind /admin and /roster.
*
* Server-only data layer (no JSX). The admin page is a server component that
* fetches these rows and passes serialisable props to the client action
* panels, so the roster and the admin table never disagree about a user.
*/
import { sql } from "drizzle-orm";
import { db } from "@/db";
import { users } from "@/db/schema";
const userName = sql<string>`coalesce(${users.displayName}, ${users.firstName} || ' ' || ${users.lastName})`;
export interface AdminUserRow {
id: string;
email: string;
displayName: string;
systemRole: string;
status: string;
}
/**
* Every user, with the ones that need attention first: pending invites, then
* invited, active, inactive, and finally denied. Alphabetical within a group.
*/
export async function listUsers(): Promise<AdminUserRow[]> {
const statusRank = sql`CASE ${users.status}
WHEN 'pending_approval' THEN 0
WHEN 'invited' THEN 1
WHEN 'active' THEN 2
WHEN 'inactive' THEN 3
ELSE 4
END`;
return db
.select({
id: users.id,
email: users.email,
displayName: userName,
systemRole: users.systemRole,
status: users.status,
})
.from(users)
.orderBy(statusRank, users.lastName, users.firstName);
}