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 = { updatedAt: new Date().toISOString() } if (body.title !== undefined) updateData.title = body.title if (body.slug !== undefined) updateData.slug = body.slug if (body.summary !== undefined) updateData.summary = body.summary if (body.content !== undefined) updateData.content = body.content if (body.category !== undefined) updateData.category = body.category if (body.coverImage !== undefined) updateData.coverImage = body.coverImage if (body.author !== undefined) updateData.author = body.author if (body.tags !== undefined) updateData.tags = JSON.stringify(Array.isArray(body.tags) ? body.tags : []) if (body.seoTitle !== undefined) updateData.seoTitle = body.seoTitle if (body.seoDesc !== undefined) updateData.seoDesc = body.seoDesc if (body.seoKeywords !== undefined) updateData.seoKeywords = body.seoKeywords if (body.published !== undefined) updateData.published = body.published ? 1 : 0 db.update(schema.articles) .set(updateData) .where(eq(schema.articles.id, id)) .run() return { success: true } })