continue scaffolding and refine the basic foundation

This commit is contained in:
Zoe
2026-01-13 19:56:24 +00:00
parent 0877cc10bd
commit 8c28946703
37 changed files with 1431 additions and 509 deletions
+16 -2
View File
@@ -1,16 +1,30 @@
import { topics } from "~~/db/schema";
import { topics, agents } from "~~/db/schema";
import { protectRoute } from "~~/server/utils/auth";
import { eq } from "drizzle-orm";
export default defineEventHandler(async (event) => {
await protectRoute(event);
const db = useDrizzle();
const userId = event.context.user.id;
const body = await readBody(event);
const { agentId, name } = body;
if (!agentId || !name) {
throw createError({ statusCode: 400, statusMessage: 'Missing required fields' });
}
const [inserted] = await db.insert(topics).values({ userId: event.context.user.id, agentId, name }).returning();
// Verify the agent belongs to this user
const [agent] = await db.select().from(agents).where(eq(agents.id, agentId));
if (!agent || agent.userId !== userId) {
throw createError({ statusCode: 403, statusMessage: 'Agent not found or unauthorized' });
}
const [inserted] = await db
.insert(topics)
.values({ userId, agentId, name })
.returning();
return inserted;
});