Skip to content

Normalize DB query results and fix admin claims for Neon direct-array responses#300

Merged
GsCommand merged 1 commit into
mainfrom
codex/fix-500-error-in-admin-claims-api
May 23, 2026
Merged

Normalize DB query results and fix admin claims for Neon direct-array responses#300
GsCommand merged 1 commit into
mainfrom
codex/fix-500-error-in-admin-claims-api

Conversation

@GsCommand
Copy link
Copy Markdown
Contributor

Motivation

  • The admin claims endpoints were failing with 500 errors when using @neondatabase/serverless because Neon can return a direct-array result shape instead of the { rows } shape returned by pg clients.
  • Normalize database result shapes so route handlers can safely consume rows regardless of driver shape and avoid runtime crashes.
  • Add tests covering both pg-style { rows: [...] } and Neon direct-array responses to prevent regressions and enable safe non-production debug data.

Description

  • Added normalizeQueryResult() and normalizeRows() to lib/db.js and made query() always return a { rows } shape by normalizing Neon direct-array results.
  • Updated api/admin/claims.js to use db.normalizeRows(result) for mapping claims and to include a safe debug object only when NODE_ENV !== 'production'.
  • Updated api/admin/claim.js to normalize claim/agent/event query results with db.normalizeRows(...) and to include the same safe non-production debug payload on failure.
  • Expanded tests/api-admin-claims.test.js to mock both pg-style and Neon direct-array query responses for list and detail endpoints and updated the test DB loader to provide normalizeRows during tests.

Testing

  • Ran npm test and all tests passed (69 tests passed, 0 failed).
  • Ran cd examples/webhook-auto-verify && npm run check and the example checks completed successfully.
  • Added unit tests in tests/api-admin-claims.test.js that exercise both { rows: [...] } and direct-array results and they succeeded under the test runs.

Codex Task

@vercel
Copy link
Copy Markdown

vercel Bot commented May 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
commandlayer-commandlayer-org Ready Ready Preview, Comment May 23, 2026 4:24pm
commandlayer-org Ready Ready Preview, Comment May 23, 2026 4:24pm
commandlayer-org111 Ready Ready Preview, Comment May 23, 2026 4:24pm

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant