Files
NightSpire/web-next/app/api/admin/gold/route.ts
T
Inna d9e6ff1496 Admin: gestión de opciones de oro (home_goldprice)
- lib/admin-gold.ts: list/create/delete sobre home_goldprice (id, gold_amount, price).
- API: POST /api/admin/gold, DELETE /api/admin/gold/[id] (403 sin admin).
- UI: /admin/gold con AdminGoldManager (alta ordenada por cantidad + borrado),
  enlace desde el índice del admin.
- i18n es/en (Admin): manageGold, gold, goldAmount, goldPrice, goldUnit, noGold.

Verificado: build OK, /admin/gold 307→login sin sesión, APIs 403 sin admin,
columnas confirmadas en la migración Django.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-13 00:35:13 +00:00

16 lines
776 B
TypeScript

import { getSession } from '@/lib/session'
import { isAdmin } from '@/lib/admin'
import { createGoldOption } from '@/lib/admin-gold'
export async function POST(request: Request) {
const session = await getSession()
if (!(await isAdmin(session))) return Response.json({ success: false, error: 'forbidden' }, { status: 403 })
let b: Record<string, unknown> = {}
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
const goldAmount = Number(b.goldAmount)
const price = Number(b.price)
if (!(goldAmount > 0) || !(price >= 0)) return Response.json({ success: false, error: 'emptyError' })
const id = await createGoldOption(goldAmount, price)
return Response.json({ success: true, id })
}