MEGAINFRA-WEBAPP/src/app/api/ask/users/route.ts

26 lines
830 B
TypeScript
Raw Normal View History

/**
* GET /api/ask/users — the "Who's using Ask?" picker list.
*
* There are no logins yet, so Ask identifies people by having them pick
* their name from the existing `users` collection. Only records with a
* non-empty `name` are offered, and only `id`/`name` are sent — never
* email, which `users` also carries.
*/
import { pbAdmin } from "@/lib/pb";
export const dynamic = "force-dynamic";
export async function GET() {
const pb = await pbAdmin();
const rows = (await pb
.collection("users")
.getFullList({ sort: "name", fields: "id,name" })) as { id: string; name?: string }[];
const users = rows
.filter((r) => !!r.name && r.name.trim().length > 0)
.map((r) => ({ id: r.id, name: r.name!.trim() }))
.sort((a, b) => a.name.localeCompare(b.name));
return Response.json({ users });
}