add delete chat

This commit is contained in:
Emily
2024-06-17 16:00:25 +02:00
parent 0797faed86
commit 90d957c593
2 changed files with 42 additions and 4 deletions

View File

@@ -105,6 +105,18 @@ const defaultPrompts = [
'How many events i got last week ?', 'How many events i got last week ?',
] ]
async function deleteChat(chat_id: string) {
if (!activeProject.value) return;
const sure = confirm("Are you sure to delete the chat ?");
if (!sure) return;
if (currentChatId.value === chat_id) {
currentChatId.value = "";
currentChatMessages.value = [];
}
await $fetch(`/api/ai/${activeProject.value._id}/${chat_id}/delete`, signHeaders());
await reloadChatsList();
}
</script> </script>
<template> <template>
@@ -213,12 +225,17 @@ const defaultPrompts = [
<div class="overflow-y-auto"> <div class="overflow-y-auto">
<div class="flex flex-col gap-2 px-2"> <div class="flex flex-col gap-2 px-2">
<div @click="openChat(chat._id.toString())" v-for="chat of chatsList?.toReversed()" <div class="flex items-center gap-4 w-full" v-for="chat of chatsList?.toReversed()">
class="bg-menu px-4 py-3 cursor-pointer hover:bg-menu/80 poppins rounded-lg" <i @click="deleteChat(chat._id.toString())"
class="fas fa-trash hover:text-gray-300 cursor-pointer"></i>
<div @click="openChat(chat._id.toString())"
class="bg-menu px-4 py-3 w-full cursor-pointer hover:bg-menu/80 poppins rounded-lg"
:class="{ '!bg-accent/60': chat._id.toString() === currentChatId }"> :class="{ '!bg-accent/60': chat._id.toString() === currentChatId }">
{{ chat.title }} {{ chat.title }}
</div> </div>
</div> </div>
</div>
</div> </div>

View File

@@ -0,0 +1,21 @@
import { getUserProjectFromId } from "~/server/LIVE_DEMO_DATA";
import { AiChatModel } from "@schema/ai/AiChatSchema";
import { sendMessageOnChat } from "~/server/services/AiService";
export default defineEventHandler(async event => {
const project_id = getRequestProjectId(event);
if (!project_id) return;
const user = getRequestUser(event);
const project = await getUserProjectFromId(project_id, user);
if (!project) return;
if (!event.context.params) return;
const chat_id = event.context.params['chat_id'];
const result = await AiChatModel.deleteOne({ _id: chat_id, project_id });
return result.deletedCount > 0;
});