Admin del foro: gestionar traducción EN de categorías y foros
Los formularios de crear categoría/foro aceptan nombre/descripción en inglés, y se añade EDICIÓN en línea de categorías (name, name_en, order) y foros (name, name_en, description, description_en). lib/admin-forum: createCategory/createForum con EN + updateCategory/updateForum; rutas PUT en category/[id] y forum/[id]. Claves Admin nuevas (nombre/descripción EN). Verificado: listado con EN + update round-trip; PUT protegido (403 sin admin). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { getSession } from '@/lib/session'
|
||||
import { isAdmin } from '@/lib/admin'
|
||||
import { deleteForum, setForumVisibility } from '@/lib/admin-forum'
|
||||
import { deleteForum, setForumVisibility, updateForum } from '@/lib/admin-forum'
|
||||
|
||||
export async function DELETE(_request: Request, { params }: { params: Promise<{ id: string }> }) {
|
||||
const session = await getSession()
|
||||
@@ -19,3 +19,20 @@ export async function PATCH(request: Request, { params }: { params: Promise<{ id
|
||||
await setForumVisibility(Number(id), b.visibility !== false)
|
||||
return Response.json({ success: true })
|
||||
}
|
||||
|
||||
export async function PUT(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
|
||||
let b: Record<string, unknown> = {}
|
||||
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
|
||||
const name = String(b.name ?? '').trim()
|
||||
const nameEn = String(b.nameEn ?? '').trim() || null
|
||||
const description = String(b.description ?? '').trim()
|
||||
const descriptionEn = String(b.descriptionEn ?? '').trim() || null
|
||||
const order = Number(b.order) || 0
|
||||
const visibility = b.visibility === false ? 0 : 1
|
||||
if (!name) return Response.json({ success: false, error: 'emptyError' })
|
||||
await updateForum(Number(id), name, nameEn, description, descriptionEn, order, visibility)
|
||||
return Response.json({ success: true })
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { getSession } from '@/lib/session'
|
||||
import { isAdmin } from '@/lib/admin'
|
||||
import { deleteCategory } from '@/lib/admin-forum'
|
||||
import { deleteCategory, updateCategory } from '@/lib/admin-forum'
|
||||
|
||||
export async function DELETE(_request: Request, { params }: { params: Promise<{ id: string }> }) {
|
||||
const session = await getSession()
|
||||
@@ -9,3 +9,17 @@ export async function DELETE(_request: Request, { params }: { params: Promise<{
|
||||
const ok = await deleteCategory(Number(id))
|
||||
return Response.json({ success: ok, error: ok ? undefined : 'categoryNotEmpty' })
|
||||
}
|
||||
|
||||
export async function PUT(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
|
||||
let b: Record<string, unknown> = {}
|
||||
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
|
||||
const name = String(b.name ?? '').trim()
|
||||
const nameEn = String(b.nameEn ?? '').trim() || null
|
||||
const order = Number(b.order) || 0
|
||||
if (!name) return Response.json({ success: false, error: 'emptyError' })
|
||||
await updateCategory(Number(id), name, nameEn, order)
|
||||
return Response.json({ success: true })
|
||||
}
|
||||
|
||||
@@ -8,8 +8,9 @@ export async function POST(request: Request) {
|
||||
let b: Record<string, unknown> = {}
|
||||
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
|
||||
const name = String(b.name ?? '').trim()
|
||||
const nameEn = String(b.nameEn ?? '').trim() || null
|
||||
const order = Number(b.order) || 0
|
||||
if (!name) return Response.json({ success: false, error: 'emptyError' })
|
||||
const id = await createCategory(name, order)
|
||||
const id = await createCategory(name, nameEn, order)
|
||||
return Response.json({ success: true, id })
|
||||
}
|
||||
|
||||
@@ -9,10 +9,12 @@ export async function POST(request: Request) {
|
||||
try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) }
|
||||
const categoryId = Number(b.categoryId)
|
||||
const name = String(b.name ?? '').trim()
|
||||
const nameEn = String(b.nameEn ?? '').trim() || null
|
||||
const description = String(b.description ?? '').trim()
|
||||
const descriptionEn = String(b.descriptionEn ?? '').trim() || null
|
||||
const order = Number(b.order) || 0
|
||||
const visibility = b.visibility === false ? 0 : 1
|
||||
if (!categoryId || !name) return Response.json({ success: false, error: 'emptyError' })
|
||||
const id = await createForum(categoryId, name, description, order, visibility)
|
||||
const id = await createForum(categoryId, name, nameEn, description, descriptionEn, order, visibility)
|
||||
return Response.json({ success: true, id })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user