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')) if (!id || isNaN(id)) { throw createError({ statusCode: 400, message: '无效的 id 参数' }) } const body = await readBody(event) if (typeof body.read !== 'boolean') { throw createError({ statusCode: 400, message: 'read 字段必须是布尔值' }) } const db = useDB() const [existing] = db .select() .from(schema.submissions) .where(eq(schema.submissions.id, id)) .all() if (!existing) { throw createError({ statusCode: 404, message: '记录不存在' }) } db.update(schema.submissions) .set({ read: body.read }) .where(eq(schema.submissions.id, id)) .run() const [updated] = db .select() .from(schema.submissions) .where(eq(schema.submissions.id, id)) .all() return { ...updated, data: JSON.parse(updated.data), } })