diff --git a/src/app/api/upload/route.ts b/src/app/api/upload/route.ts index 24992ae..aa49955 100644 --- a/src/app/api/upload/route.ts +++ b/src/app/api/upload/route.ts @@ -74,13 +74,7 @@ export async function POST(req: Request) { config = result.data } - const rawNormalized = normalizeRows(allRows, accountId, config) - - // Credit card CSVs have inverted sign semantics: CREDIT = charge, DEBIT = refund. - // Flip types so the rest of the app can treat DEBIT = spending universally. - const normalized = account.type === 'CREDIT_CARD' - ? rawNormalized.map((r) => ({ ...r, type: r.type === 'CREDIT' ? 'DEBIT' as const : 'CREDIT' as const })) - : rawNormalized + const normalized = normalizeRows(allRows, accountId, config) // Apply budget auto-assign rules (first match wins) const budgetRules = await prisma.budgetRule.findMany({ @@ -125,21 +119,6 @@ export async function POST(req: Request) { skipDuplicates: true, }) - // For CC accounts, also correct the type on any rows that already existed - // (uploaded before the CREDIT↔DEBIT flip was introduced). - if (account.type === 'CREDIT_CARD') { - const debitHashes = rowsWithBudgets.filter((r) => r.type === 'DEBIT').map((r) => r.dedupeHash) - const creditHashes = rowsWithBudgets.filter((r) => r.type === 'CREDIT').map((r) => r.dedupeHash) - await Promise.all([ - debitHashes.length > 0 - ? prisma.transaction.updateMany({ where: { dedupeHash: { in: debitHashes }, type: 'CREDIT' }, data: { type: 'DEBIT' } }) - : Promise.resolve(), - creditHashes.length > 0 - ? prisma.transaction.updateMany({ where: { dedupeHash: { in: creditHashes }, type: 'DEBIT' }, data: { type: 'CREDIT' } }) - : Promise.resolve(), - ]) - } - const skippedCount = normalized.length - importedCount // Recompute current balance