The per-account wipe works one account at a time; when every account is carrying stale cached rows (the pre-roll dates again), that's a lot of clicking. POST /api/accounts/wipe-all drops the cached rows for every account on every firm and rebuilds them all from fresh reports — firms in parallel, accounts within a firm at fetchDaysTraded's own pacing. The toolbar button confirms inline with the same 28-day-window warning. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import { getClients } from '@/lib/clients';
|
|
import { wipeAccountData } from '@/lib/db';
|
|
|
|
/**
|
|
* POST /api/accounts/wipe-all — the bulk form of /api/accounts/[id]/wipe:
|
|
* drop every account's cached rows on every firm and rebuild them all from
|
|
* fresh Tradovate reports. One report per account, so this takes a while on
|
|
* big rosters; firms run in parallel, accounts within a firm sequentially
|
|
* (that's fetchDaysTraded's own pacing against the flaky report server).
|
|
*
|
|
* Same destructive caveat as the single wipe: cached rows older than the
|
|
* report's 28-day window cannot be refetched. The UI confirms first.
|
|
*/
|
|
export async function POST() {
|
|
const clients = [...getClients().values()];
|
|
|
|
let wiped = 0;
|
|
let failedAccounts = 0;
|
|
|
|
await Promise.all(clients.map(async (client) => {
|
|
for (const account of client.accountList) {
|
|
wipeAccountData(account.id);
|
|
delete client.dailyPnL[account.id];
|
|
delete client.fullDailyPnL[account.id];
|
|
delete client.daysTraded[account.id];
|
|
delete client.priorProfit[account.id];
|
|
delete client.lastFundDates[account.id];
|
|
delete client.fundTransactions[account.id];
|
|
delete client.lastFetchErrors[account.name];
|
|
delete client.lastFetchRaw[account.name];
|
|
wiped++;
|
|
}
|
|
const result = await client.fetchDaysTraded();
|
|
failedAccounts += result.failedAccounts;
|
|
}));
|
|
|
|
return NextResponse.json({ ok: true, wiped, failedAccounts });
|
|
}
|