Add a wipe & recalculate button to the account detail page

Cached daily P&L rows outlive what the Cash History report still
produces (stale pre-roll dates being the recent example), and nothing
deletes them any more. POST /api/accounts/[id]/wipe drops the account's
cached P&L, fund transactions and meta, clears the in-memory view, and
rebuilds from a fresh report — fetchDaysTraded now takes an optional
account filter so one account doesn't cost a report round-trip on every
other. The button confirms inline first: rows older than the report's
28-day window cannot be refetched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Brandon Li
2026-09-08 21:27:34 -05:00
co-authored by Claude Fable 5
parent bd72c4b1f6
commit 5a69ea2f64
4 changed files with 128 additions and 1 deletions
+13
View File
@@ -282,6 +282,19 @@ export function loadAccountMeta(accountId: number, key: string): string | null {
return row?.value ?? null;
}
/** Deletes every cached row for an account — daily P&L, fund transactions and
* meta — so the next report fetch rebuilds it from scratch. Rows older than
* the report's 28-day window are gone for good; that is the point (stale
* pre-roll dates), but it is why callers confirm first. */
export function wipeAccountData(accountId: number): void {
const txn = db.transaction(() => {
db.prepare('DELETE FROM daily_pnl WHERE account_id = ?').run(accountId);
db.prepare('DELETE FROM fund_transactions WHERE account_id = ?').run(accountId);
db.prepare('DELETE FROM account_meta WHERE account_id = ?').run(accountId);
});
txn();
}
// ── AutoBuyer captures ───────────────────────────────────────────────────────
db.exec(`