useRuntimeConfig() and better-sqlite3 were being called at module top-level, which crashes during Nitro server startup. Now all DB access is lazy via useDb(), and auth uses process.env directly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
22 lines
654 B
TypeScript
22 lines
654 B
TypeScript
import { useDb } from '../../utils/db'
|
|
import { requireAdmin } from '../../utils/auth'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
requireAdmin(event)
|
|
const db = useDb()
|
|
const id = getRouterParam(event, 'id')
|
|
const body = await readBody(event)
|
|
|
|
if (body.hidden !== undefined) {
|
|
db.prepare('UPDATE ideas SET hidden = ? WHERE id = ?').run(body.hidden ? 1 : 0, id)
|
|
}
|
|
if (body.text !== undefined) {
|
|
db.prepare('UPDATE ideas SET text = ? WHERE id = ?').run(body.text, id)
|
|
}
|
|
if (body.category !== undefined) {
|
|
db.prepare('UPDATE ideas SET category = ? WHERE id = ?').run(body.category, id)
|
|
}
|
|
|
|
return { ok: true }
|
|
})
|