first commit

This commit is contained in:
2026-01-17 14:17:42 +05:30
commit 0f194eb9e7
328 changed files with 73544 additions and 0 deletions

86
app/api/payouts/route.ts Normal file
View File

@@ -0,0 +1,86 @@
import { NextRequest, NextResponse } from 'next/server'
import { auth } from '@/auth'
import { prisma } from '@/lib/prisma'
import { getSystemSettings } from '@/lib/settings'
export async function GET() {
try {
const session = await auth()
if (!session?.user?.id) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const payouts = await prisma.payout.findMany({
where: { userId: session.user.id },
orderBy: { createdAt: 'desc' }
})
return NextResponse.json(payouts)
} catch (error) {
console.error('Error fetching payouts:', error)
return NextResponse.json(
{ error: 'Failed to fetch payouts' },
{ status: 500 }
)
}
}
export async function POST(request: NextRequest) {
try {
const session = await auth()
if (!session?.user?.id) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const { amount, bankDetails } = await request.json()
const settings = await getSystemSettings()
if (amount < settings.minimumPayout) {
return NextResponse.json(
{ error: `Minimum payout amount is ₹${settings.minimumPayout}` },
{ status: 400 }
)
}
const wallet = await prisma.wallet.findUnique({
where: { userId: session.user.id }
})
if (!wallet || wallet.balance < amount) {
return NextResponse.json(
{ error: 'Insufficient balance' },
{ status: 400 }
)
}
const result = await prisma.$transaction(async (tx) => {
const payout = await tx.payout.create({
data: {
userId: session.user.id,
amount,
bankDetails,
status: 'PENDING'
}
})
await tx.wallet.update({
where: { userId: session.user.id },
data: {
balance: { decrement: amount }
}
})
return payout
})
return NextResponse.json(result)
} catch (error) {
console.error('Error creating payout request:', error)
return NextResponse.json(
{ error: 'Failed to create payout request' },
{ status: 500 }
)
}
}