23 lines
748 B
TypeScript
23 lines
748 B
TypeScript
import { NextResponse } from 'next/server'
|
|
import { PrismaClient } from '@/app/generated/prisma'
|
|
|
|
export async function POST(request: Request) {
|
|
const prisma = new PrismaClient()
|
|
try {
|
|
const body = await request.json().catch(() => ({})) as any
|
|
const id = String(body?.id || '')
|
|
const costPerView = Number(body?.costPerView)
|
|
if (!id || !Number.isFinite(costPerView)) {
|
|
return NextResponse.json({ error: 'invalid payload' }, { status: 400 })
|
|
}
|
|
await prisma.handle.update({ where: { id }, data: { costPerView } })
|
|
return NextResponse.json({ ok: true })
|
|
} catch (e) {
|
|
return NextResponse.json({ error: 'update failed' }, { status: 500 })
|
|
} finally {
|
|
try { await prisma.$disconnect() } catch {}
|
|
}
|
|
}
|
|
|
|
|