33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import { NextResponse } from "next/server"
|
|
import { getCollection } from "@/lib/db/mongo"
|
|
|
|
function mapId(doc: Record<string, unknown> & { _id: { toString(): string } }) {
|
|
return { ...doc, id: doc._id.toString() }
|
|
}
|
|
|
|
export async function GET() {
|
|
try {
|
|
const [txColl, rcColl, wdColl] = await Promise.all([
|
|
getCollection("transactions"),
|
|
getCollection("rechargeOrders"),
|
|
getCollection("withdrawOrders"),
|
|
])
|
|
const [tx, rc, wd] = await Promise.all([
|
|
txColl.find({}).sort({ createdAt: -1 }).limit(300).toArray(),
|
|
rcColl.find({}).sort({ createdAt: -1 }).limit(200).toArray(),
|
|
wdColl.find({}).sort({ createdAt: -1 }).limit(200).toArray(),
|
|
])
|
|
return NextResponse.json({
|
|
success: true,
|
|
data: {
|
|
transactions: tx.map(mapId),
|
|
recharges: rc.map(mapId),
|
|
withdraws: wd.map(mapId),
|
|
},
|
|
})
|
|
} catch (e) {
|
|
console.error("GET /api/admin/finance error:", e)
|
|
return NextResponse.json({ success: false, error: String(e) }, { status: 500 })
|
|
}
|
|
}
|