fix(18): decouple campaigns count-query params from list-query placeholder numbering
The count query reused statusFilter (built with $3 against the list query's 3-element params array) but only passed a 1-element params array, causing a Postgres bind-parameter mismatch (500) on any `?status=` filtered request. Pre-existing since 18-03; surfaced by the 18-04 gap-closure code re-review. Gives the count query its own independent param array/placeholder numbering.
This commit is contained in:
parent
d3373ab708
commit
650f9b8100
1 changed files with 9 additions and 2 deletions
|
|
@ -50,9 +50,16 @@ export async function GET(request: NextRequest) {
|
|||
params
|
||||
);
|
||||
|
||||
const countParams: unknown[] = [];
|
||||
let countFilter = '';
|
||||
if (status) {
|
||||
countParams.push(status);
|
||||
countFilter = `WHERE status = $${countParams.length}`;
|
||||
}
|
||||
|
||||
const totalRes = await postgresClient.query<{ count: string }>(
|
||||
`SELECT COUNT(*)::text AS count FROM campaigns ${statusFilter}`,
|
||||
status ? [status] : []
|
||||
`SELECT COUNT(*)::text AS count FROM campaigns ${countFilter}`,
|
||||
countParams
|
||||
);
|
||||
const total = parseInt(totalRes.rows[0]?.count ?? '0', 10);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue