import { and, eq } from "drizzle-orm"; import { topics } from "~~/drizzle/schema"; import { db } from "~~/server/lib/db"; import * as z from 'zod'; export default defineEventHandler(async (event) => { await protectRoute(event); const userId = event.context.user!.id; const topicId = getRouterParam(event, 'topicId')!; const res = await db.delete(topics).where(and(eq(topics.id, topicId), eq(topics.userId, userId))); if (res.rowCount === 0) { throw createError({ statusCode: 400, statusMessage: 'Invalid topic', }); } return { ok: true }; });