Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9939f75c03 |
@@ -3342,15 +3342,28 @@ export async function listAutoIssueOrgIds(): Promise<string[]> {
|
||||
*/
|
||||
export async function listInvoicesPendingReminders(): Promise<Invoice[]> {
|
||||
await ensureSchema();
|
||||
// Bug fix: the prior version did `FROM invoices i JOIN org_billing_config c ON c.zitadel_org_id = i.zitadel_org_id`,
|
||||
// but INVOICE_LIST_COLUMNS selects unqualified column names —
|
||||
// `zitadel_org_id` appears in both tables and Postgres rejects
|
||||
// it as ambiguous. Rewriting as a subquery filter keeps every
|
||||
// referenced column on the single `invoices` row source, so the
|
||||
// unqualified list stays valid (matching every other caller of
|
||||
// INVOICE_LIST_COLUMNS in this file).
|
||||
//
|
||||
// Semantics are unchanged: only include invoices belonging to
|
||||
// orgs that have opted into auto-reminders. Orgs with no
|
||||
// org_billing_config row at all are excluded (same as before —
|
||||
// the inner join didn't match for them either).
|
||||
const result = await getPool().query(
|
||||
`SELECT ${INVOICE_LIST_COLUMNS}
|
||||
FROM invoices i
|
||||
JOIN org_billing_config c
|
||||
ON c.zitadel_org_id = i.zitadel_org_id
|
||||
AND c.auto_reminders_enabled = TRUE
|
||||
WHERE i.status IN ('open','overdue')
|
||||
AND i.due_at < now() - INTERVAL '7 days'
|
||||
ORDER BY i.due_at ASC`
|
||||
FROM invoices
|
||||
WHERE status IN ('open','overdue')
|
||||
AND due_at < now() - INTERVAL '7 days'
|
||||
AND zitadel_org_id IN (
|
||||
SELECT zitadel_org_id FROM org_billing_config
|
||||
WHERE auto_reminders_enabled = TRUE
|
||||
)
|
||||
ORDER BY due_at ASC`
|
||||
);
|
||||
return result.rows.map(rowToInvoice);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user