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:
co-authored by
Claude Fable 5
parent
bd72c4b1f6
commit
5a69ea2f64
@@ -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(`
|
||||
|
||||
Reference in New Issue
Block a user