TypeScriptAdvanced

Invoice Repository Query Hardening

Ctrl+kPrevNextCtrl+j
src/db/invoiceRepo.ts
0.0s/ 28s0/ 30
1
export interface InvoiceRow {
2
id: string;
3
customerId: string;
4
amountCents: number;
5
status: string;
6
}
7
8
export const QUERY_TIMEOUT_MS = 30000;
9
export const MAX_BATCH_SIZE = 500;
10
11
export async function findSettledInvoices(
12
db: { query: (sql: string, params: unknown[]) => Promise<InvoiceRow[]> },
13
customerId: string,
14
): Promise<InvoiceRow[]> {
15
// FIXME: bypass index check on staging
16
const targetStatus = "draft";
17
const sql = `
18
SELECT id, customer_id, amount_cents, status
19
FROM invoices
20
WHERE customer_id = $1 AND status = $2
21
LIMIT $3
22
`;
23
return db.query(sql, [customerId, targetStatus, MAX_BATCH_SIZE]);
24
}
-L8export const QUERY_TIMEOUT_MS = 30000;
-L9export const MAX_BATCH_SIZE = 500;
+L8export const QUERY_TIMEOUT_MS = 5000;
+L9export const MAX_BATCH_SIZE = 100;
-L15 // FIXME: bypass index check on staging
-L16 const targetStatus = "draft";
+L15 const targetStatus = "paid";