29 行
1.3 KiB
JavaScript
29 行
1.3 KiB
JavaScript
import { eq } from 'drizzle-orm'
|
|
import { useDB, schema } from '../../../utils/db.js'
|
|
import { requireAdmin } from '../../../utils/auth.js'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
requireAdmin(event)
|
|
|
|
const id = Number(getRouterParam(event, 'id'))
|
|
const body = await readBody(event)
|
|
const db = useDB()
|
|
|
|
const updateData = {}
|
|
if (body.author !== undefined) updateData.author = body.author
|
|
if (body.rating !== undefined) updateData.rating = body.rating
|
|
if (body.title !== undefined) updateData.title = body.title
|
|
if (body.content !== undefined) updateData.content = body.content
|
|
if (body.date !== undefined) updateData.date = body.date
|
|
if (body.screenshot !== undefined) updateData.screenshot = body.screenshot
|
|
if (body.scenes !== undefined) updateData.scenes = Array.isArray(body.scenes) ? JSON.stringify(body.scenes) : body.scenes
|
|
if (body.concerns !== undefined) updateData.concerns = Array.isArray(body.concerns) ? JSON.stringify(body.concerns) : body.concerns
|
|
if (body.verified !== undefined) updateData.verified = body.verified ? 1 : 0
|
|
if (body.published !== undefined) updateData.published = body.published ? 1 : 0
|
|
if (body.sortOrder !== undefined) updateData.sortOrder = body.sortOrder
|
|
|
|
db.update(schema.reviews).set(updateData).where(eq(schema.reviews.id, id)).run()
|
|
|
|
return { success: true }
|
|
})
|