-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeleteChat.ts
More file actions
33 lines (30 loc) · 1.06 KB
/
deleteChat.ts
File metadata and controls
33 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"use server";
import { z } from "zod";
import { deleteChat, initContext, revalidateChat } from "@/lib/chatHistory";
import { section } from "@/schema/chat";
import { eq } from "drizzle-orm";
import { withServerActionInstrumentation } from "@sentry/nextjs";
import { headers } from "next/headers";
export async function deleteChatAction(chatId: string) {
return withServerActionInstrumentation(
"deleteChatAction", // Action name for Sentry
{
headers: await headers(), // Connect client and server traces
recordResponse: true, // Include response data
},
async () => {
chatId = z.uuid().parse(chatId);
const ctx = await initContext();
if (!ctx.userId) {
throw new Error("Not authenticated");
}
const deletedChat = await deleteChat(chatId, ctx);
const targetSection = await ctx.drizzle.query.section.findFirst({
where: eq(section.sectionId, deletedChat[0].sectionId),
});
if (targetSection) {
await revalidateChat(chatId, ctx.userId, targetSection.pagePath);
}
}
);
}