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>
This commit is contained in:
2026-07-13 00:35:13 +00:00
parent 36a4354ff7
commit d9e6ff1496
8 changed files with 179 additions and 2 deletions
+11
View File
@@ -0,0 +1,11 @@
import { getSession } from '@/lib/session'
import { isAdmin } from '@/lib/admin'
import { deleteGoldOption } from '@/lib/admin-gold'
export async function DELETE(_request: Request, { params }: { params: Promise<{ id: string }> }) {
const session = await getSession()
if (!(await isAdmin(session))) return Response.json({ success: false, error: 'forbidden' }, { status: 403 })
const { id } = await params
await deleteGoldOption(Number(id))
return Response.json({ success: true })
}
+15
View File
@@ -0,0 +1,15 @@
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 })
}