Remove CC type flip — normalizer already produces correct DEBIT/CREDIT for Discover CC

This commit is contained in:
2026-04-21 10:59:59 -04:00
parent a9c12b94e1
commit 62ca178308

View File

@@ -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