3fe32d923e
Build & Auto-Repair / build (push) Has been cancelled
- 86 catch blocks in 49 API route files now return the actual error message via error.message
- 14 campaign/lead/config catch blocks that lacked console.error now log errors
- 17 client pages/components now show toast.error notifications on API failures
- Silent .catch(() => {}) and finally-only try blocks now surface errors to users
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { NextResponse } from "next/server"
|
|
import { getSessionUser } from "@/lib/auth"
|
|
import { query } from "@/lib/db"
|
|
|
|
export async function GET() {
|
|
try {
|
|
const user = await getSessionUser()
|
|
if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
|
|
|
|
const result = await query(
|
|
`SELECT u.id, u.first_name, u.last_name, u.email,
|
|
ur.role_id, r.name AS role_name, r.display_name AS role_display
|
|
FROM users u
|
|
LEFT JOIN user_roles ur ON ur.user_id = u.id
|
|
LEFT JOIN roles r ON r.id = ur.role_id
|
|
WHERE u.deleted_at IS NULL AND u.id != $1
|
|
ORDER BY u.first_name ASC`,
|
|
[user.id],
|
|
)
|
|
|
|
const users = result.rows.map((r: any) => ({
|
|
id: r.id,
|
|
name: `${r.first_name} ${r.last_name}`,
|
|
email: r.email,
|
|
role: r.role_display || r.role_name || "",
|
|
}))
|
|
|
|
return NextResponse.json({ users })
|
|
} catch (error) {
|
|
console.error("Event users error:", error)
|
|
const message = error instanceof Error ? error.message : "Failed to load users"
|
|
return NextResponse.json({ error: message }, { status: 500 })
|
|
}
|
|
}
|