feat: add functionality to clear category assignments from transactions and display categorized count in settings
This commit is contained in:
24
app/api/banking/transactions/clear-categories/route.ts
Normal file
24
app/api/banking/transactions/clear-categories/route.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import { prisma } from "@/lib/prisma"
|
||||
|
||||
export async function POST() {
|
||||
try {
|
||||
const result = await prisma.transaction.updateMany({
|
||||
where: {
|
||||
categoryId: { not: null },
|
||||
},
|
||||
data: {
|
||||
categoryId: null,
|
||||
},
|
||||
})
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
count: result.count,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("Error clearing categories:", error)
|
||||
return NextResponse.json({ error: "Failed to clear categories" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user