import { eq } from 'drizzle-orm'; import { app, db, schema } from '@/app.ts'; app.route({ path: 'n5-make', key: 'update', middleware: ['auth'], description: `更新 Make, 参数: id: Make ID, 必填 slug: 唯一业务ID, 选填 resources: 资源列表(数组), 选填 `, }).define(async (ctx) => { const tokenUser = ctx.state.tokenUser; const { id, userId, createdAt, updatedAt, ...rest } = ctx.query.data || {}; if (!id) { ctx.throw(400, 'id 参数缺失'); } const existing = await db.select().from(schema.n5Make).where(eq(schema.n5Make.id, id)).limit(1); if (existing.length === 0) { ctx.throw(404, 'Make 不存在'); } if (existing[0].userId !== tokenUser.id) { ctx.throw(403, '没有权限更新该 Make'); } const result = await db.update(schema.n5Make).set({ ...rest }).where(eq(schema.n5Make.id, id)).returning(); ctx.body = result[0]; return ctx; }).addTo(app);