Remove CC type flip — normalizer already produces correct DEBIT/CREDIT for Discover CC
This commit is contained in:
@@ -74,13 +74,7 @@ export async function POST(req: Request) {
|
|||||||
config = result.data
|
config = result.data
|
||||||
}
|
}
|
||||||
|
|
||||||
const rawNormalized = normalizeRows(allRows, accountId, config)
|
const normalized = 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
|
|
||||||
|
|
||||||
// Apply budget auto-assign rules (first match wins)
|
// Apply budget auto-assign rules (first match wins)
|
||||||
const budgetRules = await prisma.budgetRule.findMany({
|
const budgetRules = await prisma.budgetRule.findMany({
|
||||||
@@ -125,21 +119,6 @@ export async function POST(req: Request) {
|
|||||||
skipDuplicates: true,
|
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
|
const skippedCount = normalized.length - importedCount
|
||||||
|
|
||||||
// Recompute current balance
|
// Recompute current balance
|
||||||
|
|||||||
Reference in New Issue
Block a user